From 067748cae21cb6d9725b3b491d71b4cefc000e45 Mon Sep 17 00:00:00 2001 From: Deepanshu Date: Thu, 23 Mar 2023 16:46:08 +0530 Subject: [PATCH] Completed --- lib/main.dart | 10 +- lib/router.dart | 31 ++- lib/splash_screen.dart | 113 ++++++----- lib/views/home_screen.dart | 384 +++++++++++++++++++------------------ pubspec.lock | 12 +- 5 files changed, 300 insertions(+), 250 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 649e9e1e..68ca3160 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,10 +11,12 @@ import 'package:overlay_support/overlay_support.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); EnvironmentConfig.loadEnvVariables(); - SystemChrome.setPreferredOrientations([ - DeviceOrientation.portraitUp, - DeviceOrientation.portraitDown, - ]); + SystemChrome.setPreferredOrientations( + [ + DeviceOrientation.portraitUp, + DeviceOrientation.portraitDown, + ], + ); setupLocator(); localNotif.initialize(); await hiveDb.init(); diff --git a/lib/router.dart b/lib/router.dart index 7b568bb4..5525e2d3 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -10,25 +10,36 @@ Route generateRoute(RouteSettings settings) { switch (settings.name) { case Routes.authScreen: return MaterialPageRoute( - builder: (context) => const AuthScreen(key: Key('auth'))); + builder: (context) => const AuthScreen( + key: Key('auth'), + ), + ); case Routes.mainScreen: return MaterialPageRoute( - builder: (context) => const MainScreen(key: Key('MainScreen'))); + builder: (context) => const MainScreen( + key: Key('MainScreen'), + ), + ); case Routes.hikeScreen: HikeScreen arguments = settings.arguments; return MaterialPageRoute( - builder: (context) => HikeScreen( - arguments.beacon, - isLeader: arguments.isLeader, - )); + builder: (context) => HikeScreen( + arguments.beacon, + isLeader: arguments.isLeader, + ), + ); case Routes.groupScreen: GroupScreen arguments = settings.arguments; return MaterialPageRoute( - builder: (context) => GroupScreen( - arguments.group, - )); + builder: (context) => GroupScreen( + arguments.group, + ), + ); default: return MaterialPageRoute( - builder: (context) => const SplashScreen(key: Key('SplashScreen'))); + builder: (context) => const SplashScreen( + key: Key('SplashScreen'), + ), + ); } } diff --git a/lib/splash_screen.dart b/lib/splash_screen.dart index c862c487..c2ef4693 100644 --- a/lib/splash_screen.dart +++ b/lib/splash_screen.dart @@ -22,64 +22,87 @@ class _SplashScreenState extends State { bool isCheckingUrl = false; Future _handleInitialUri() async { - _sub = uriLinkStream.listen((Uri uri) { - if (!mounted) return; - setState(() { - _latestUri = uri; - }); - }, onError: (Object err) { - if (!mounted) return; - setState(() { - _latestUri = null; - }); - }); + _sub = uriLinkStream.listen( + (Uri uri) { + if (!mounted) return; + setState( + () { + _latestUri = uri; + }, + ); + }, + onError: (Object err) { + if (!mounted) return; + setState( + () { + _latestUri = null; + }, + ); + }, + ); try { final uri = await getInitialUri(); if (!mounted) return; setState(() => _initialUri = uri); } on PlatformException { if (!mounted) return; - setState(() => _initialUri = null); + setState( + () => _initialUri = null, + ); } on FormatException catch (err) { - debugPrint(err.toString()); + debugPrint( + err.toString(), + ); if (!mounted) return; - setState(() => _initialUri = null); + setState( + () => _initialUri = null, + ); } await databaseFunctions.init(); - await userConfig.userLoggedIn().then((value) async { - if (_latestUri == null && _initialUri == null) { - if (value || hiveDb.currentUserBox.containsKey('user')) { - navigationService.pushReplacementScreen('/main'); - } else { - navigationService.pushReplacementScreen('/auth'); - } - } else { - if (_initialUri != null) { - var shortcode = _initialUri.queryParameters['shortcode']; - if (value) { - await databaseFunctions.joinBeacon(shortcode).then((val) { - if (val != null) { - navigationService.pushScreen('/hikeScreen', - arguments: HikeScreen(val, isLeader: false)); - } else { - navigationService.pushReplacementScreen('/main'); - } - }); + await userConfig.userLoggedIn().then( + (value) async { + if (_latestUri == null && _initialUri == null) { + if (value || hiveDb.currentUserBox.containsKey('user')) { + navigationService.pushReplacementScreen('/main'); } else { - // login in anonymously and join hike - await databaseFunctions.signup(name: "Anonymous"); - await databaseFunctions.joinBeacon(shortcode).then((val) async { - if (value != null) { - navigationService.pushScreen('/hikeScreen', - arguments: HikeScreen(val, isLeader: false)); - } else { - navigationService.pushReplacementScreen('/main'); - } - }); + navigationService.pushReplacementScreen('/auth'); + } + } else { + if (_initialUri != null) { + var shortcode = _initialUri.queryParameters['shortcode']; + if (value) { + await databaseFunctions.joinBeacon(shortcode).then( + (val) { + if (val != null) { + navigationService.pushScreen( + '/hikeScreen', + arguments: HikeScreen(val, isLeader: false), + ); + } else { + navigationService.pushReplacementScreen('/main'); + } + }, + ); + } else { + // login in anonymously and join hike + await databaseFunctions.signup(name: "Anonymous"); + await databaseFunctions.joinBeacon(shortcode).then( + (val) async { + if (value != null) { + navigationService.pushScreen( + '/hikeScreen', + arguments: HikeScreen(val, isLeader: false), + ); + } else { + navigationService.pushReplacementScreen('/main'); + } + }, + ); + } } } - } - }); + }, + ); } @override diff --git a/lib/views/home_screen.dart b/lib/views/home_screen.dart index c855ff4d..8716936d 100644 --- a/lib/views/home_screen.dart +++ b/lib/views/home_screen.dart @@ -75,171 +75,179 @@ class _MainScreenState extends State with TickerProviderStateMixin { Widget build(BuildContext context) { return WillPopScope( onWillPop: _onPopHome, - child: BaseView(builder: (context, model, child) { - TabController tabController = new TabController(length: 1, vsync: this); - return model.isBusy - ? LoadingScreen() - : Scaffold( - resizeToAvoidBottomInset: false, - body: SafeArea( - child: ModalProgressHUD( - inAsyncCall: model.isCreatingGroup, - child: Stack( - children: [ - CustomPaint( - size: Size(MediaQuery.of(context).size.width, - MediaQuery.of(context).size.height - 200), - painter: ShapePainter(), - ), - Align( - alignment: Alignment(0.9, -0.8), - child: FloatingActionButton( - onPressed: () => showDialog( - context: context, - builder: (context) => AlertDialog( - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(10.0), - ), - actionsAlignment: - MainAxisAlignment.spaceEvenly, - title: Text( - (userConfig.currentUser.isGuest) - ? 'Create Account' - : 'Logout', - style: TextStyle( - fontSize: 25, color: kYellow), - ), - content: Text( - (userConfig.currentUser.isGuest) - ? 'Would you like to create an account?' - : 'Are you sure you wanna logout?', - style: TextStyle( - fontSize: 16, color: kBlack), - ), - actions: [ - HikeButton( - buttonHeight: 2.5.h, - buttonWidth: 8.w, - onTap: () => - Navigator.of(context).pop(false), - text: 'No', - textSize: 18.0, + child: BaseView( + builder: (context, model, child) { + TabController tabController = + new TabController(length: 1, vsync: this); + return model.isBusy + ? LoadingScreen() + : Scaffold( + resizeToAvoidBottomInset: false, + body: SafeArea( + child: ModalProgressHUD( + inAsyncCall: model.isCreatingGroup, + child: Stack( + children: [ + CustomPaint( + size: Size(MediaQuery.of(context).size.width, + MediaQuery.of(context).size.height - 200), + painter: ShapePainter(), + ), + Align( + alignment: Alignment(0.9, -0.8), + child: FloatingActionButton( + onPressed: () => showDialog( + context: context, + builder: (context) => AlertDialog( + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(10.0), ), - HikeButton( - buttonHeight: 2.5.h, - buttonWidth: 8.w, - onTap: () { - navigationService.pop(); - model.logout(); - }, - text: 'Yes', - textSize: 18.0, + actionsAlignment: + MainAxisAlignment.spaceEvenly, + title: Text( + (userConfig.currentUser.isGuest) + ? 'Create Account' + : 'Logout', + style: TextStyle( + fontSize: 25, color: kYellow), ), - ], - )), - backgroundColor: kYellow, - child: (userConfig.currentUser.isGuest) - ? Icon(Icons.person) - : Icon(Icons.logout), + content: Text( + (userConfig.currentUser.isGuest) + ? 'Would you like to create an account?' + : 'Are you sure you wanna logout?', + style: TextStyle( + fontSize: 16, color: kBlack), + ), + actions: [ + HikeButton( + buttonHeight: 2.5.h, + buttonWidth: 8.w, + onTap: () => Navigator.of(context) + .pop(false), + text: 'No', + textSize: 18.0, + ), + HikeButton( + buttonHeight: 2.5.h, + buttonWidth: 8.w, + onTap: () { + navigationService.pop(); + model.logout(); + }, + text: 'Yes', + textSize: 18.0, + ), + ], + )), + backgroundColor: kYellow, + child: (userConfig.currentUser.isGuest) + ? Icon(Icons.person) + : Icon(Icons.logout), + ), ), - ), - Padding( - padding: EdgeInsets.fromLTRB(4.w, 25.h, 4.w, 5), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - mainAxisSize: MainAxisSize.max, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - width: 45.w, - child: HikeButton( - buttonWidth: homebwidth - 10, - buttonHeight: homebheight - 2, - text: 'Create Group', - textColor: Colors.white, - borderColor: Colors.white, - buttonColor: kYellow, - onTap: () { - if (userConfig.currentUser.isGuest) { - navigationService.showSnackBar( - 'You need to login with credentials to be able to create a group'); - } else { - CreateJoinGroupDialog.createGroupDialog( - context, model); - } - }, + Padding( + padding: EdgeInsets.fromLTRB(4.w, 25.h, 4.w, 5), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + mainAxisSize: MainAxisSize.max, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + width: 45.w, + child: HikeButton( + buttonWidth: homebwidth - 10, + buttonHeight: homebheight - 2, + text: 'Create Group', + textColor: Colors.white, + borderColor: Colors.white, + buttonColor: kYellow, + onTap: () { + if (userConfig.currentUser.isGuest) { + navigationService.showSnackBar( + 'You need to login with credentials to be able to create a group', + ); + } else { + CreateJoinGroupDialog.createGroupDialog( + context, model); + } + }, + ), ), - ), - SizedBox( - width: 1.w, - ), - Container( - width: 45.w, - child: HikeButton( - buttonWidth: homebwidth, - buttonHeight: homebheight - 2, - text: 'Join a Group', - textColor: kYellow, - borderColor: kYellow, - buttonColor: Colors.white, - onTap: () async { - CreateJoinGroupDialog.joinGroupDialog( - context, model); - }, + SizedBox( + width: 1.w, ), - ), - ], + Container( + width: 45.w, + child: HikeButton( + buttonWidth: homebwidth, + buttonHeight: homebheight - 2, + text: 'Join a Group', + textColor: kYellow, + borderColor: kYellow, + buttonColor: Colors.white, + onTap: () async { + CreateJoinGroupDialog.joinGroupDialog( + context, + model, + ); + }, + ), + ), + ], + ), ), - ), - Column( - mainAxisAlignment: MainAxisAlignment.end, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Container( - height: - MediaQuery.of(context).size.height * 0.565, - margin: EdgeInsets.only(top: 20), - decoration: BoxDecoration( + Column( + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Container( + height: + MediaQuery.of(context).size.height * 0.565, + margin: EdgeInsets.only(top: 20), + decoration: BoxDecoration( color: kLightBlue, borderRadius: BorderRadius.only( - topLeft: const Radius.circular(50.0), - topRight: const Radius.circular(50.0))), - child: Column( - children: [ - TabBar( - indicatorSize: TabBarIndicatorSize.tab, - indicatorColor: kBlue, - labelColor: kBlack, - tabs: [ - Tab(text: 'Your Groups'), - ], - controller: tabController, + topLeft: const Radius.circular(50.0), + topRight: const Radius.circular(50.0), ), - Expanded( - child: TabBarView( + ), + child: Column( + children: [ + TabBar( + indicatorSize: TabBarIndicatorSize.tab, + indicatorColor: kBlue, + labelColor: kBlack, + tabs: [ + Tab(text: 'Your Groups'), + ], controller: tabController, - children: [ - Padding( - padding: const EdgeInsets.all(12.0), - child: FutureBuilder( - future: fetchingUserGroups, - builder: (context, snapshot) { - if (snapshot.connectionState == - ConnectionState.done) { - if (snapshot.hasError) { - return Center( - child: Text( - snapshot.error.toString(), - textAlign: - TextAlign.center, - textScaleFactor: 1.3, - ), - ); - } - final List posts = - snapshot.data; - return Container( + ), + Expanded( + child: TabBarView( + controller: tabController, + children: [ + Padding( + padding: const EdgeInsets.all(12.0), + child: FutureBuilder( + future: fetchingUserGroups, + builder: (context, snapshot) { + if (snapshot.connectionState == + ConnectionState.done) { + if (snapshot.hasError) { + return Center( + child: Text( + snapshot.error + .toString(), + textAlign: + TextAlign.center, + textScaleFactor: 1.3, + ), + ); + } + final List posts = + snapshot.data; + return Container( alignment: Alignment.center, child: posts.length == 0 ? SingleChildScrollView( @@ -274,18 +282,22 @@ class _MainScreenState extends State with TickerProviderStateMixin { 20), children: [ TextSpan( - text: - 'Join', - style: - TextStyle(fontWeight: FontWeight.bold)), + text: + 'Join', + style: TextStyle( + fontWeight: + FontWeight.bold), + ), TextSpan( text: ' a Group or '), TextSpan( - text: - 'Create', - style: - TextStyle(fontWeight: FontWeight.bold)), + text: + 'Create', + style: TextStyle( + fontWeight: + FontWeight.bold), + ), TextSpan( text: ' a new one! '), @@ -310,34 +322,36 @@ class _MainScreenState extends State with TickerProviderStateMixin { index) { return GroupCustomWidgets .getGroupCard( - context, - posts[ - index]); + context, + posts[index], + ); }, - )); - } else { - return Center( - child: BeaconCustomWidgets - .getPlaceholder(), - ); - } - }, + ), + ); + } else { + return Center( + child: BeaconCustomWidgets + .getPlaceholder(), + ); + } + }, + ), ), - ), - ], + ], + ), ), - ), - ], + ], + ), ), - ), - ], - ), - ], + ], + ), + ], + ), ), ), - ), - ); - }), + ); + }, + ), ); } } diff --git a/pubspec.lock b/pubspec.lock index 95dc7a97..5a600ba2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -633,7 +633,7 @@ packages: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.5" + version: "0.2.0" meta: dependency: transitive description: @@ -974,7 +974,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.9.1" stack_trace: dependency: transitive description: @@ -1016,21 +1016,21 @@ packages: name: test url: "https://pub.dartlang.org" source: hosted - version: "1.21.4" + version: "1.21.5" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.12" + version: "0.4.13" test_core: dependency: transitive description: name: test_core url: "https://pub.dartlang.org" source: hosted - version: "0.4.16" + version: "0.4.17" timezone: dependency: transitive description: @@ -1121,7 +1121,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.2" + version: "2.1.3" vm_service: dependency: transitive description: