selfprivacy.org.app/lib/ui/pages/onboarding/onboarding.dart

149 lines
4 KiB
Dart
Raw Normal View History

2020-11-29 20:07:46 +00:00
import 'package:flutter/material.dart';
2021-01-06 17:35:57 +00:00
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart';
2020-11-29 20:07:46 +00:00
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
2020-12-08 19:26:51 +00:00
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
2020-12-06 07:28:31 +00:00
import 'package:selfprivacy/utils/route_transitions/basic.dart';
2021-03-15 15:39:44 +00:00
import 'package:easy_localization/easy_localization.dart';
2020-11-29 20:07:46 +00:00
2020-12-30 14:13:25 +00:00
class OnboardingPage extends StatefulWidget {
2021-03-15 15:39:44 +00:00
const OnboardingPage({Key? key, required this.nextPage}) : super(key: key);
2020-11-29 20:07:46 +00:00
2021-01-06 17:35:57 +00:00
final Widget nextPage;
2020-12-30 14:13:25 +00:00
@override
_OnboardingPageState createState() => _OnboardingPageState();
}
class _OnboardingPageState extends State<OnboardingPage> {
PageController pageController = PageController();
@override
void initState() {
super.initState();
}
2020-11-29 20:07:46 +00:00
@override
Widget build(BuildContext context) {
2020-12-06 07:28:31 +00:00
return SafeArea(
child: Scaffold(
2020-12-30 14:13:25 +00:00
body: PageView(
controller: pageController,
children: [
_withPadding(firstPage()),
_withPadding(secondPage()),
],
),
),
);
}
Widget _withPadding(Widget child) {
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 15,
),
child: child,
);
}
Widget firstPage() {
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 30),
BrandText.h2(
2021-03-15 15:39:44 +00:00
'onboarding.page1_title'.tr(),
),
2020-12-30 14:13:25 +00:00
SizedBox(height: 20),
2021-03-18 00:55:38 +00:00
BrandText.body2('services.page1_text'.tr()),
2020-12-30 14:13:25 +00:00
Flexible(
child: Center(
child: Image.asset(
2021-02-17 16:20:09 +00:00
_fileName(
context: context,
path: 'assets/images/onboarding',
fileExtention: 'png',
fileName: 'onboarding1',
),
2020-12-30 14:13:25 +00:00
),
),
2020-12-06 07:28:31 +00:00
),
2020-12-30 14:13:25 +00:00
BrandButton.rised(
onPressed: () {
pageController.animateToPage(
1,
duration: Duration(milliseconds: 300),
curve: Curves.easeIn,
);
},
2021-03-15 15:39:44 +00:00
title: 'basis.next'.tr(),
2020-12-30 14:13:25 +00:00
),
SizedBox(height: 30),
],
),
);
}
Widget secondPage() {
return ConstrainedBox(
constraints: BoxConstraints(
maxHeight: MediaQuery.of(context).size.height,
),
child: Column(
children: [
SizedBox(height: 30),
2021-03-15 15:39:44 +00:00
BrandText.h2('onboarding.page2_title'.tr()),
2020-12-30 14:13:25 +00:00
SizedBox(height: 20),
2021-03-15 15:39:44 +00:00
BrandText.body2('onboarding.page2_text'.tr()),
2020-12-30 14:13:25 +00:00
SizedBox(height: 20),
Center(
child: Image.asset(
2021-02-17 16:20:09 +00:00
_fileName(
context: context,
path: 'assets/images/onboarding',
fileExtention: 'png',
fileName: 'logos_line',
),
2020-12-30 14:13:25 +00:00
),
),
Flexible(
child: Center(
child: Image.asset(
2021-02-17 16:20:09 +00:00
_fileName(
context: context,
path: 'assets/images/onboarding',
fileExtention: 'png',
fileName: 'onboarding2',
),
2020-12-06 07:28:31 +00:00
),
2020-12-30 14:13:25 +00:00
),
2020-12-06 07:28:31 +00:00
),
2020-12-30 14:13:25 +00:00
BrandButton.rised(
onPressed: () {
2021-01-06 17:35:57 +00:00
context.read<AppSettingsCubit>().turnOffOnboarding();
2020-12-30 14:13:25 +00:00
Navigator.of(context)
2021-01-06 17:35:57 +00:00
.pushReplacement(materialRoute(widget.nextPage));
2020-12-30 14:13:25 +00:00
},
2021-03-15 15:39:44 +00:00
title: 'basis.got_it'.tr(),
2020-12-30 14:13:25 +00:00
),
SizedBox(height: 30),
],
2020-12-03 16:52:53 +00:00
),
);
}
}
2021-02-17 16:20:09 +00:00
String _fileName({
2021-03-15 15:39:44 +00:00
required BuildContext context,
required String path,
required String fileName,
required String fileExtention,
2021-02-17 16:20:09 +00:00
}) {
var theme = Theme.of(context);
var isDark = theme.brightness == Brightness.dark;
return '$path/$fileName${isDark ? '-dark' : '-light'}.$fileExtention';
}