From 95400d7ee2c90008e362c91f043d13dfc6ac8df0 Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Sat, 3 Sep 2022 18:05:53 -0400 Subject: [PATCH] Initial pull-down gesture for student ID --- lib/src/layouts/main/index.dart | 6 --- lib/src/routes/index.dart | 7 ++- lib/src/routes/index.gr.dart | 48 +++++++++-------- lib/src/screens/home/index.dart | 71 ++++++++++++++---------- lib/src/screens/student_id/index.dart | 72 +++++++++++++++---------- lib/src/widgets/scroll_view_height.dart | 8 ++- 6 files changed, 127 insertions(+), 85 deletions(-) diff --git a/lib/src/layouts/main/index.dart b/lib/src/layouts/main/index.dart index b804df5..466ce17 100644 --- a/lib/src/layouts/main/index.dart +++ b/lib/src/layouts/main/index.dart @@ -1,5 +1,4 @@ import 'package:auto_route/auto_route.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:furman_now/src/routes/index.gr.dart'; @@ -37,7 +36,6 @@ class _MainLayoutState extends State { routes: const [ HomeRoute(), MapRoute(), - StudentIdRoute(), EventsRoute(), InfoRoute(), ], @@ -71,10 +69,6 @@ class _MainLayoutState extends State { icon: Icon(Icons.map), label: 'Map', ), - BottomNavigationBarItem( - icon: Icon(Icons.perm_identity), - label: 'Meal Card', - ), BottomNavigationBarItem( icon: Icon(Icons.calendar_month), label: 'Events', diff --git a/lib/src/routes/index.dart b/lib/src/routes/index.dart index e5400ec..9278cba 100644 --- a/lib/src/routes/index.dart +++ b/lib/src/routes/index.dart @@ -13,10 +13,15 @@ import '../layouts/main/index.dart'; AutoRoute(path: "/", page: MainLayout, children: [ AutoRoute(path: "home", page: HomeScreen), AutoRoute(path: "map", page: MapScreen), - AutoRoute(path: "student-id", page: StudentIdScreen), AutoRoute(path: "events", page: EventsScreen), AutoRoute(path: "info", page: InfoScreen), ]), + CustomRoute( + path: "/student-id", + page: StudentIdScreen, + transitionsBuilder: TransitionsBuilders.slideTop, + durationInMilliseconds: 200, + ), ], ) class $AppRouter {} \ No newline at end of file diff --git a/lib/src/routes/index.gr.dart b/lib/src/routes/index.gr.dart index 244e358..b7140df 100644 --- a/lib/src/routes/index.gr.dart +++ b/lib/src/routes/index.gr.dart @@ -16,10 +16,10 @@ import 'package:flutter/material.dart' as _i8; import '../layouts/main/index.dart' as _i1; import '../screens/events/index.dart' as _i5; -import '../screens/home/index.dart' as _i2; +import '../screens/home/index.dart' as _i3; import '../screens/info/index.dart' as _i6; -import '../screens/map/index.dart' as _i3; -import '../screens/student_id/index.dart' as _i4; +import '../screens/map/index.dart' as _i4; +import '../screens/student_id/index.dart' as _i2; class AppRouter extends _i7.RootStackRouter { AppRouter([_i8.GlobalKey<_i8.NavigatorState>? navigatorKey]) @@ -31,17 +31,22 @@ class AppRouter extends _i7.RootStackRouter { return _i7.MaterialPageX( routeData: routeData, child: const _i1.MainLayout()); }, + StudentIdRoute.name: (routeData) { + return _i7.CustomPage( + routeData: routeData, + child: const _i2.StudentIdScreen(), + transitionsBuilder: _i7.TransitionsBuilders.slideTop, + durationInMilliseconds: 200, + opaque: true, + barrierDismissible: false); + }, HomeRoute.name: (routeData) { return _i7.MaterialPageX( - routeData: routeData, child: const _i2.HomeScreen()); + routeData: routeData, child: const _i3.HomeScreen()); }, MapRoute.name: (routeData) { return _i7.MaterialPageX( - routeData: routeData, child: const _i3.MapScreen()); - }, - StudentIdRoute.name: (routeData) { - return _i7.MaterialPageX( - routeData: routeData, child: const _i4.StudentIdScreen()); + routeData: routeData, child: const _i4.MapScreen()); }, EventsRoute.name: (routeData) { return _i7.MaterialPageX( @@ -59,12 +64,11 @@ class AppRouter extends _i7.RootStackRouter { _i7.RouteConfig(HomeRoute.name, path: 'home', parent: MainLayout.name), _i7.RouteConfig(MapRoute.name, path: 'map', parent: MainLayout.name), - _i7.RouteConfig(StudentIdRoute.name, - path: 'student-id', parent: MainLayout.name), _i7.RouteConfig(EventsRoute.name, path: 'events', parent: MainLayout.name), _i7.RouteConfig(InfoRoute.name, path: 'info', parent: MainLayout.name) - ]) + ]), + _i7.RouteConfig(StudentIdRoute.name, path: '/student-id') ]; } @@ -78,7 +82,15 @@ class MainLayout extends _i7.PageRouteInfo { } /// generated route for -/// [_i2.HomeScreen] +/// [_i2.StudentIdScreen] +class StudentIdRoute extends _i7.PageRouteInfo { + const StudentIdRoute() : super(StudentIdRoute.name, path: '/student-id'); + + static const String name = 'StudentIdRoute'; +} + +/// generated route for +/// [_i3.HomeScreen] class HomeRoute extends _i7.PageRouteInfo { const HomeRoute() : super(HomeRoute.name, path: 'home'); @@ -86,21 +98,13 @@ class HomeRoute extends _i7.PageRouteInfo { } /// generated route for -/// [_i3.MapScreen] +/// [_i4.MapScreen] class MapRoute extends _i7.PageRouteInfo { const MapRoute() : super(MapRoute.name, path: 'map'); static const String name = 'MapRoute'; } -/// generated route for -/// [_i4.StudentIdScreen] -class StudentIdRoute extends _i7.PageRouteInfo { - const StudentIdRoute() : super(StudentIdRoute.name, path: 'student-id'); - - static const String name = 'StudentIdRoute'; -} - /// generated route for /// [_i5.EventsScreen] class EventsRoute extends _i7.PageRouteInfo { diff --git a/lib/src/screens/home/index.dart b/lib/src/screens/home/index.dart index 81f4e94..6c2d09c 100644 --- a/lib/src/screens/home/index.dart +++ b/lib/src/screens/home/index.dart @@ -1,3 +1,4 @@ +import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:furman_now/src/routes/index.gr.dart'; import 'package:furman_now/src/utils/greeting.dart'; @@ -54,34 +55,48 @@ class HomeScreen extends StatelessWidget { ), ), ), - ScrollViewWithHeight( - child: Container( - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.vertical(top: Radius.circular(30)), - ), - padding: const EdgeInsets.symmetric(vertical: 20), - margin: const EdgeInsets.only(top: 200), - width: double.infinity, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const HeaderWidget( - title: "Today's Events", - link: HeaderLink(text: "View more", href: EventsRoute()), - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20), - child: EventsList(), - ), - const HeaderWidget(title: "Food & Dining"), - const RestaurantsList(), - const HeaderWidget(title: "Transportation"), - const Padding( - padding: EdgeInsets.symmetric(horizontal: 20), - child: TransportationCard(), - ), - ], + NotificationListener( + onNotification: (notification) { + if (notification is ScrollUpdateNotification) { + final offset = notification.metrics.pixels; + if (offset < 0) { + var offsetAmount = offset.abs(); + if (offsetAmount > 50) { + context.router.navigate(const StudentIdRoute()); + } + } + } + return true; + }, + child: ScrollViewWithHeight( + child: Container( + decoration: const BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.vertical(top: Radius.circular(30)), + ), + padding: const EdgeInsets.symmetric(vertical: 20), + margin: const EdgeInsets.only(top: 200), + width: double.infinity, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const HeaderWidget( + title: "Today's Events", + link: HeaderLink(text: "View more", href: EventsRoute()), + ), + Padding( + padding: const EdgeInsets.symmetric(horizontal: 20), + child: EventsList(), + ), + const HeaderWidget(title: "Food & Dining"), + const RestaurantsList(), + const HeaderWidget(title: "Transportation"), + const Padding( + padding: EdgeInsets.symmetric(horizontal: 20), + child: TransportationCard(), + ), + ], + ), ), ), ), diff --git a/lib/src/screens/student_id/index.dart b/lib/src/screens/student_id/index.dart index 129b8c9..b301e26 100644 --- a/lib/src/screens/student_id/index.dart +++ b/lib/src/screens/student_id/index.dart @@ -1,7 +1,9 @@ import 'dart:async'; +import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:barcode_widget/barcode_widget.dart'; +import 'package:furman_now/src/routes/index.gr.dart'; import 'package:furman_now/src/services/get_app/barcode/barcode_service.dart'; import 'package:furman_now/src/utils/theme.dart'; @@ -26,6 +28,12 @@ class _StudentIdScreenState extends State { ); } + @override + void dispose() { + super.dispose(); + timer?.cancel(); + } + void updateBarcode(Timer timer) { setState(() { barcodeNumber = BarcodeService.generateGetBarcode(); @@ -35,35 +43,45 @@ class _StudentIdScreenState extends State { @override Widget build(BuildContext context) { return Scaffold( - body: Container( - color: const Color(0xffb7acc9), - child: SafeArea( - child: ListView( - padding: const EdgeInsets.all(40), - children: [ - Text( - "Furman ID", - style: furmanTextStyle(const TextStyle(color: Color(0xff26183d), fontSize: 36, fontWeight: FontWeight.w800)), - ), - const SizedBox(height: 200), - Container( - decoration: const BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(10)), + body: Listener( + onPointerMove: (details) { + int sensitivity = 8; + if (details.delta.dy > sensitivity) { + // Down Swipe + } else if (details.delta.dy < -sensitivity) { + context.router.navigate(const MainLayout()); + } + }, + child: Container( + color: const Color(0xffb7acc9), + child: SafeArea( + child: ListView( + padding: const EdgeInsets.all(40), + children: [ + Text( + "Furman ID", + style: furmanTextStyle(const TextStyle(color: Color(0xff26183d), fontSize: 36, fontWeight: FontWeight.w800)), ), - // hack since the barcode has a weird intrinsic size for some reason - child: LayoutBuilder( - builder: (BuildContext context, BoxConstraints constraints) { - return BarcodeWidget( - barcode: Barcode.pdf417(moduleHeight: 4), - data: barcodeNumber, - margin: const EdgeInsets.all(10), - height: constraints.maxWidth / 3, - ); - }, + const SizedBox(height: 200), + Container( + decoration: const BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(10)), + ), + // hack since the barcode has a weird intrinsic size for some reason + child: LayoutBuilder( + builder: (BuildContext context, BoxConstraints constraints) { + return BarcodeWidget( + barcode: Barcode.pdf417(moduleHeight: 4), + data: barcodeNumber, + margin: const EdgeInsets.all(10), + height: constraints.maxWidth / 3, + ); + }, + ), ), - ), - ], + ], + ), ), ), ), diff --git a/lib/src/widgets/scroll_view_height.dart b/lib/src/widgets/scroll_view_height.dart index 6619ee7..7b3a275 100644 --- a/lib/src/widgets/scroll_view_height.dart +++ b/lib/src/widgets/scroll_view_height.dart @@ -12,8 +12,14 @@ class ScrollViewWithHeight extends StatelessWidget { Widget build(BuildContext context) { return LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) { return SingleChildScrollView( + physics: const BouncingScrollPhysics( + parent: AlwaysScrollableScrollPhysics() + ), child: ConstrainedBox( - constraints: constraints.copyWith(minHeight: constraints.maxHeight, maxHeight: double.infinity), + constraints: constraints.copyWith( + minHeight: constraints.maxHeight, + maxHeight: double.infinity + ), child: child, ), );