From 088cd51c4f892eb1aa3eaaad94622b8f8df1fb1c Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 29 Dec 2023 13:23:08 +0200 Subject: [PATCH] Moved to a new app dialog --- lib/presentation/atoms/atoms.dart | 1 + lib/presentation/atoms/button_atom.dart | 69 ++++++++++++++++++++ lib/presentation/pages/splash_page.dart | 85 ++++++++++++++++++++----- 3 files changed, 139 insertions(+), 16 deletions(-) create mode 100644 lib/presentation/atoms/button_atom.dart diff --git a/lib/presentation/atoms/atoms.dart b/lib/presentation/atoms/atoms.dart index b2d00dc9..77f552e6 100644 --- a/lib/presentation/atoms/atoms.dart +++ b/lib/presentation/atoms/atoms.dart @@ -1,4 +1,5 @@ export 'bottom_navigation_bar_item_atom.dart'; +export 'button_atom.dart'; export 'circular_progress_indicator_atom.dart'; export 'image_atom.dart'; export 'margined_expanded_atom.dart'; diff --git a/lib/presentation/atoms/button_atom.dart b/lib/presentation/atoms/button_atom.dart new file mode 100644 index 00000000..3df34941 --- /dev/null +++ b/lib/presentation/atoms/button_atom.dart @@ -0,0 +1,69 @@ +import 'package:cybear_jinni/presentation/atoms/atoms.dart'; +import 'package:flutter/material.dart'; + +class ButtonWidgetAtom extends StatelessWidget { + const ButtonWidgetAtom({ + required this.variant, + required this.onPressed, + super.key, + this.text, + this.icon, + this.disabled = false, + this.disableActionType = false, + this.translate = true, + }); + + final ButtonVariant variant; + final VoidCallback onPressed; + final String? text; + final IconData? icon; + double get width => 250; + double get _height => 60; + final bool disabled; + final bool translate; + final bool disableActionType; + + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final TextTheme textTheme = themeData.textTheme; + final ColorScheme colorScheme = themeData.colorScheme; + + if (variant == ButtonVariant.primary) { + return Container( + constraints: const BoxConstraints( + minWidth: 300, + ), + height: _height, + child: FilledButton.icon( + onPressed: onPressed, + style: FilledButton.styleFrom().copyWith( + alignment: Alignment.center, + backgroundColor: disabled + ? MaterialStateProperty.all(colorScheme.surfaceVariant) + : null, + ), + icon: Icon(icon), + label: TextAtom( + text ?? '', + translate: translate, + maxLines: 1, + style: textTheme.bodyLarge!.copyWith( + color: colorScheme.onPrimary, + ), + ), + ), + ); + } + return const Text('Type is not supported yet'); + } +} + +enum ButtonVariant { + primary, + secondary, + tertiary, + action, + actionToggled, + back, +} diff --git a/lib/presentation/pages/splash_page.dart b/lib/presentation/pages/splash_page.dart index 2bee8e61..d6e02b51 100644 --- a/lib/presentation/pages/splash_page.dart +++ b/lib/presentation/pages/splash_page.dart @@ -1,11 +1,7 @@ -import 'dart:io'; - import 'package:auto_route/auto_route.dart'; -import 'package:cybear_jinni/domain/i_local_db_repository.dart'; import 'package:cybear_jinni/presentation/atoms/atoms.dart'; -import 'package:cybear_jinni/presentation/core/routes/app_router.gr.dart'; -import 'package:flutter/foundation.dart' show kIsWeb; import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; @RoutePage() class SplashPage extends StatefulWidget { @@ -18,21 +14,32 @@ class _SplashPageState extends State { void initState() { super.initState(); - _navigate(); + // _navigate(); + openUpdateDialog(); } - Future _navigate() async { - (await ILocalDbRepository.instance.getHubEntityNetworkName()).fold( - (l) { - if (kIsWeb || Platform.isLinux || Platform.isWindows) { - return context.router.replace(const ConnectToHubRoute()); - } - return context.router.replace(const IntroductionRouteRoute()); - }, - (r) => context.router.replace(const HomeRoute()), - ); + Future openUpdateDialog() async { + await Future.delayed(const Duration(seconds: 1)); + if (context.mounted) { + await showDialog( + context: context, + builder: (BuildContext context) => UpdateDialog(), + ); + } } + // Future _navigate() async { + // (await ILocalDbRepository.instance.getHubEntityNetworkName()).fold( + // (l) { + // if (kIsWeb || Platform.isLinux || Platform.isWindows) { + // return context.router.replace(const ConnectToHubRoute()); + // } + // return context.router.replace(const IntroductionRouteRoute()); + // }, + // (r) => context.router.replace(const HomeRoute()), + // ); + // } + @override Widget build(BuildContext context) { return const Scaffold( @@ -44,3 +51,49 @@ class _SplashPageState extends State { ); } } + +class UpdateDialog extends StatelessWidget { + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final TextTheme textTheme = themeData.textTheme; + final ColorScheme colorScheme = themeData.colorScheme; + + return Center( + child: AlertDialog( + title: TextAtom('A New App', style: textTheme.titleLarge), + content: SizedBox( + height: 170, + child: Column( + children: [ + TextAtom( + 'We have moved to a new app.\n' + 'Please download the new app and delete this one.\n' + 'See you in the other side :D', + style: textTheme.titleMedium, + ), + const Expanded( + child: SizedBox(), + ), + ElevatedButton( + child: TextAtom( + 'Download', + style: textTheme.titleMedium, + ), + onPressed: () { + launchUrl( + Uri.parse( + 'https://play.google.com/store/apps/details?id=com.cybearjinni.app', + ), + mode: LaunchMode.externalApplication, + ); + }, + ), + ], + ), + ), + actions: [], + ), + ); + } +}