update onboarding; add missing safe areas
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
@@ -25,11 +27,17 @@ import 'package:weblibre/core/providers/defaults.dart';
|
||||
import 'package:weblibre/core/providers/router.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/entities/tab_container_selection.dart';
|
||||
import 'package:weblibre/features/geckoview/domain/repositories/tab.dart';
|
||||
import 'package:weblibre/features/geckoview/features/browser/domain/services/browser_addon.dart';
|
||||
import 'package:weblibre/features/geckoview/features/tabs/data/entities/tab_mode.dart';
|
||||
import 'package:weblibre/features/onboarding/domain/entities/onboarding_mode.dart';
|
||||
import 'package:weblibre/features/onboarding/domain/providers.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/abstract/i_form_page.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/ai_configuration.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/default_search.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/doh_settings.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/permissions.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/privacy_hardening.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/toolbar_layout.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/ublock_opt_in.dart';
|
||||
import 'package:weblibre/features/onboarding/presentation/pages/welcome.dart';
|
||||
import 'package:weblibre/features/user/domain/repositories/onboarding.dart';
|
||||
@@ -50,6 +58,12 @@ class OnboardingScreen extends HookConsumerWidget {
|
||||
final disableAnimations = MediaQuery.disableAnimationsOf(context);
|
||||
|
||||
final pageController = usePageController();
|
||||
final eulaAccepted = ref.watch(eulaAcceptedProvider);
|
||||
final onboardingMode = ref.watch(onboardingModeProvider);
|
||||
|
||||
final isReturningUser = currentRevision == 2;
|
||||
final showDetailedPages =
|
||||
isReturningUser || onboardingMode == OnboardingMode.detailed;
|
||||
|
||||
final pages = useMemoized<List<Widget>>(() {
|
||||
switch (currentRevision) {
|
||||
@@ -57,122 +71,156 @@ class OnboardingScreen extends HookConsumerWidget {
|
||||
return [const AiConfigurationPage()];
|
||||
default:
|
||||
return [
|
||||
const WelcomePage(),
|
||||
WelcomePage(isReturningUser: isReturningUser),
|
||||
const DefaultSearchPage(),
|
||||
if (showDetailedPages) const DohSettingsPage(),
|
||||
if (showDetailedPages) const ToolbarLayoutPage(),
|
||||
const PrivacyHardeningPage(),
|
||||
const AiConfigurationPage(),
|
||||
UBlockOptInPage(formKey: GlobalKey<FormState>()),
|
||||
if (showDetailedPages)
|
||||
UBlockOptInPage(formKey: GlobalKey<FormState>()),
|
||||
PermissionsPage(formKey: GlobalKey<FormState>()),
|
||||
];
|
||||
}
|
||||
}, [currentRevision, targetRevision]);
|
||||
}, [currentRevision, targetRevision, onboardingMode]);
|
||||
|
||||
final lastPage = useRef(pageController.initialPage);
|
||||
final currentPage = useState(pageController.initialPage);
|
||||
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PageView(
|
||||
controller: pageController,
|
||||
children: pages,
|
||||
onPageChanged: (value) {
|
||||
if (value > lastPage.value) {
|
||||
if (pages[lastPage.value] case final IFormPage formPage) {
|
||||
formPage.formKey.currentState?.save();
|
||||
return PopScope(
|
||||
canPop: currentPage.value == 0,
|
||||
onPopInvokedWithResult: (didPop, _) async {
|
||||
if (didPop) return;
|
||||
if (disableAnimations) {
|
||||
pageController.jumpToPage(currentPage.value - 1);
|
||||
} else {
|
||||
await pageController.previousPage(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: PageView(
|
||||
controller: pageController,
|
||||
physics: currentPage.value == 0 && !eulaAccepted
|
||||
? const NeverScrollableScrollPhysics()
|
||||
: null,
|
||||
children: pages,
|
||||
onPageChanged: (value) {
|
||||
if (value > lastPage.value) {
|
||||
if (pages[lastPage.value] case final IFormPage formPage) {
|
||||
formPage.formKey.currentState?.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastPage.value = value;
|
||||
currentPage.value = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Visibility(
|
||||
visible: currentPage.value > 0,
|
||||
child: TextButton.icon(
|
||||
onPressed: () async {
|
||||
if (disableAnimations) {
|
||||
pageController.jumpToPage(currentPage.value - 1);
|
||||
} else {
|
||||
await pageController.previousPage(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
label: const Text('Previous'),
|
||||
),
|
||||
),
|
||||
lastPage.value = value;
|
||||
currentPage.value = value;
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: SmoothPageIndicator(
|
||||
controller: pageController,
|
||||
count: pages.length,
|
||||
effect: WormEffect(
|
||||
dotColor: theme.colorScheme.onSurface,
|
||||
activeDotColor: theme.colorScheme.primary,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Visibility(
|
||||
visible: currentPage.value > 0,
|
||||
child: TextButton.icon(
|
||||
onPressed: () async {
|
||||
if (disableAnimations) {
|
||||
pageController.jumpToPage(currentPage.value - 1);
|
||||
} else {
|
||||
await pageController.previousPage(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
label: const Text('Previous'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (currentPage.value < pages.length - 1)
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () async {
|
||||
if (disableAnimations) {
|
||||
pageController.jumpToPage(currentPage.value + 1);
|
||||
} else {
|
||||
await pageController.nextPage(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
},
|
||||
iconAlignment: IconAlignment.end,
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
label: const Text('Next'),
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () async {
|
||||
if (pages[currentPage.value]
|
||||
case final IFormPage formPage) {
|
||||
formPage.formKey.currentState?.save();
|
||||
}
|
||||
|
||||
await ref
|
||||
.read(onboardingRepositoryProvider.notifier)
|
||||
.pushRevision(targetRevision);
|
||||
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: ref.read(docsUriProvider),
|
||||
tabMode: TabMode.regular,
|
||||
containerSelection:
|
||||
const TabContainerSelection.unassigned(),
|
||||
selectTab: true,
|
||||
);
|
||||
|
||||
ref.invalidate(routerProvider);
|
||||
},
|
||||
iconAlignment: IconAlignment.end,
|
||||
icon: const Icon(Icons.done),
|
||||
label: const Text('Done'),
|
||||
child: Center(
|
||||
child: SmoothPageIndicator(
|
||||
controller: pageController,
|
||||
count: pages.length,
|
||||
effect: WormEffect(
|
||||
activeDotColor: theme.colorScheme.primary,
|
||||
dotHeight: 10.0,
|
||||
dotWidth: 10.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (currentPage.value < pages.length - 1)
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: currentPage.value == 0 && !eulaAccepted
|
||||
? null
|
||||
: () async {
|
||||
if (disableAnimations) {
|
||||
pageController.jumpToPage(
|
||||
currentPage.value + 1,
|
||||
);
|
||||
} else {
|
||||
await pageController.nextPage(
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
},
|
||||
iconAlignment: IconAlignment.end,
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
label: const Text('Next'),
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: TextButton.icon(
|
||||
onPressed: () async {
|
||||
if (pages[currentPage.value]
|
||||
case final IFormPage formPage) {
|
||||
formPage.formKey.currentState?.save();
|
||||
}
|
||||
|
||||
if (onboardingMode == OnboardingMode.express) {
|
||||
unawaited(
|
||||
ref
|
||||
.read(browserAddonServiceProvider.notifier)
|
||||
.install('uBlock0@raymondhill.net'),
|
||||
);
|
||||
}
|
||||
|
||||
await ref
|
||||
.read(onboardingRepositoryProvider.notifier)
|
||||
.pushRevision(targetRevision);
|
||||
|
||||
await ref
|
||||
.read(tabRepositoryProvider.notifier)
|
||||
.addTab(
|
||||
url: ref.read(docsUriProvider),
|
||||
tabMode: TabMode.regular,
|
||||
containerSelection:
|
||||
const TabContainerSelection.unassigned(),
|
||||
selectTab: true,
|
||||
);
|
||||
|
||||
ref.invalidate(routerProvider);
|
||||
},
|
||||
iconAlignment: IconAlignment.end,
|
||||
icon: const Icon(Icons.done),
|
||||
label: const Text('Done'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user