From 0c2cd55afa400ceb62e8284e0ec463adca2f209c Mon Sep 17 00:00:00 2001 From: Felix Holz Date: Fri, 16 Feb 2024 00:54:46 +0100 Subject: [PATCH] frustrations with bottom sheets --- lib/main.dart | 75 ++++++----- lib/misc/bottom_sheet.dart | 54 +++++--- lib/screens/bottom_navigation_screen.dart | 122 +++++++++--------- .../standard_elements/frederic_scaffold.dart | 22 ++-- pubspec.yaml | 6 +- 5 files changed, 152 insertions(+), 127 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f995209..b1229e9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:isolate'; +import 'package:cupertino_modal_sheet/cupertino_modal_sheet.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; @@ -184,38 +185,48 @@ class _FredericBaseState extends State { value: FredericBackend.instance.goalManager), ], child: MaterialApp( - showPerformanceOverlay: false, - title: 'NeverSkip Fitness', - locale: context.locale, - debugShowCheckedModeBanner: false, - supportedLocales: context.supportedLocales, - localizationsDelegates: context.localizationDelegates, - theme: ThemeData( - useMaterial3: false, - primaryColor: theme.mainColor, - brightness: theme.isBright ? Brightness.light : Brightness.dark, - fontFamily: 'Montserrat', - colorScheme: ColorScheme.fromSwatch().copyWith( - secondary: theme.accentColor, - primary: theme.mainColor, - brightness: - theme.isBright ? Brightness.light : Brightness.dark)), - home: FredericMainApp() - // OrientationBuilder( - // builder: (context, orientation) { - // if (orientation == Orientation.portrait) { - // return FredericMainApp(); - // } - // - // if (getIt.isRegistered()) - // getIt.unregister(); - // getIt.registerSingleton(AdminBackend()); - // return BlocProvider.value( - // value: AdminBackend.instance.iconManager, - // child: FredericAdminPanel()); - // }, - // ), - ), + showPerformanceOverlay: false, + title: 'NeverSkip Fitness', + locale: context.locale, + debugShowCheckedModeBanner: false, + supportedLocales: context.supportedLocales, + localizationsDelegates: context.localizationDelegates, + theme: ThemeData( + useMaterial3: false, + primaryColor: theme.mainColor, + brightness: theme.isBright ? Brightness.light : Brightness.dark, + fontFamily: 'Montserrat', + colorScheme: ColorScheme.fromSwatch().copyWith( + secondary: theme.accentColor, + primary: theme.mainColor, + brightness: + theme.isBright ? Brightness.light : Brightness.dark)), + onGenerateRoute: (RouteSettings settings) { + switch (settings.name) { + case '/': + return CupertinoModalSheetRoute( + settings: settings, + builder: (context) { + return FredericMainApp(); + }); + } + }, + //home: FredericMainApp() + // OrientationBuilder( + // builder: (context, orientation) { + // if (orientation == Orientation.portrait) { + // return FredericMainApp(); + // } + // + // if (getIt.isRegistered()) + // getIt.unregister(); + // getIt.registerSingleton(AdminBackend()); + // return BlocProvider.value( + // value: AdminBackend.instance.iconManager, + // child: FredericAdminPanel()); + // }, + // ), + ), ), ); } diff --git a/lib/misc/bottom_sheet.dart b/lib/misc/bottom_sheet.dart index 5871579..5e32693 100644 --- a/lib/misc/bottom_sheet.dart +++ b/lib/misc/bottom_sheet.dart @@ -1,30 +1,46 @@ +import 'package:cupertino_modal_sheet/cupertino_modal_sheet.dart'; import 'package:flutter/cupertino.dart'; -import 'package:smooth_sheets/smooth_sheets.dart'; +import 'package:flutter/material.dart'; Future showFredericBottomSheet( {required BuildContext context, bool enableDrag = false, bool isDismissible = true, required Widget Function(BuildContext) builder}) { - // Use `CupertinoModalSheetRoute` to show an ios 15 style modal sheet. - // For declarative navigation (Navigator 2.0), use `CupertinoModalSheetPage` instead. - print("WERNER FINDENIG"); - final modalRoute = CupertinoModalSheetRoute( - builder: (context) => DraggableSheet( - child: DecoratedBox( - decoration: const ShapeDecoration( - color: CupertinoColors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.all( - Radius.circular(16), - ), - ), - ), - child: SizedBox.expand( - child: Builder(builder: builder), - )))); + return showCupertinoModalSheet( + context: context, + builder: builder, + ); - return Navigator.push(context, modalRoute); + // return showModalBottomSheet( + // context: context, + // shape: const RoundedRectangleBorder( + // borderRadius: BorderRadius.vertical( + // top: Radius.circular(25.0), + // ), + // ), + // builder: (c) => + // Container(height: MediaQuery.of(context).size.height * 0.9)); + // + // // Use `CupertinoModalSheetRoute` to show an ios 15 style modal sheet. + // // For declarative navigation (Navigator 2.0), use `CupertinoModalSheetPage` instead. + // print("WERNER FINDENIG"); + // final modalRoute = CupertinoModalSheetRoute( + // builder: (context) => DraggableSheet( + // child: DecoratedBox( + // decoration: const ShapeDecoration( + // color: CupertinoColors.white, + // shape: RoundedRectangleBorder( + // borderRadius: BorderRadius.all( + // Radius.circular(16), + // ), + // ), + // ), + // child: SizedBox.expand( + // child: Builder(builder: builder), + // )))); + // + // return Navigator.push(context, modalRoute); } // Future showFredericBottomSheetOld( diff --git a/lib/screens/bottom_navigation_screen.dart b/lib/screens/bottom_navigation_screen.dart index c28c235..b878ba4 100644 --- a/lib/screens/bottom_navigation_screen.dart +++ b/lib/screens/bottom_navigation_screen.dart @@ -1,3 +1,4 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:frederic/backend/backend.dart'; @@ -40,67 +41,72 @@ class _BottomNavigationScreenState extends State @override Widget build(BuildContext context) { - return Scaffold( - backgroundColor: Colors.black, - extendBodyBehindAppBar: false, - body: AnnotatedRegion( - value: theme.isDark || theme.isColorful - ? SystemUiOverlayStyle.light - : SystemUiOverlayStyle.dark, - child: PageView( - children: screens, - controller: pageController, - onPageChanged: (index) { - setState(() { - currentIndex = index; - }); - _sendCurrentTabToAnalytics(); - }, + return CupertinoPageScaffold( + child: Scaffold( + backgroundColor: Colors.black, + extendBodyBehindAppBar: false, + body: AnnotatedRegion( + value: theme.isDark || theme.isColorful + ? SystemUiOverlayStyle.light + : SystemUiOverlayStyle.dark, + child: PageView( + children: screens, + controller: pageController, + onPageChanged: (index) { + setState(() { + currentIndex = index; + }); + _sendCurrentTabToAnalytics(); + }, + ), ), - ), - bottomNavigationBar: Stack( - children: [ - // Weird workaround to make the space behind the corners - // the correct colors - Container(color: Colors.white, height: kBottomNavigationBarHeight), - Container( - decoration: BoxDecoration( - color: theme.backgroundColor, - borderRadius: BorderRadius.only( - topRight: Radius.circular(12), topLeft: Radius.circular(12)), - boxShadow: [ - BoxShadow( - color: Color(0x17000000), spreadRadius: 0, blurRadius: 3), - ], - ), - child: ClipRRect( - borderRadius: BorderRadius.only( - topLeft: Radius.circular(12), topRight: Radius.circular(12)), - child: BottomNavigationBar( - items: items, - elevation: 0, - backgroundColor: - theme.isColorful ? theme.mainColor : theme.backgroundColor, - selectedItemColor: theme.isColorful - ? theme.textColorColorfulBackground - : theme.accentColor, - unselectedItemColor: theme.isColorful - ? theme.textColorColorfulBackground - : theme.mainColor, - showUnselectedLabels: true, - type: BottomNavigationBarType.fixed, - currentIndex: currentIndex, - onTap: (index) { - HapticFeedback.selectionClick(); - setState(() { - currentIndex = index; - pageController.jumpToPage(index); - }); - }, + bottomNavigationBar: Stack( + children: [ + // Weird workaround to make the space behind the corners + // the correct colors + Container(color: Colors.white, height: kBottomNavigationBarHeight), + Container( + decoration: BoxDecoration( + color: theme.backgroundColor, + borderRadius: BorderRadius.only( + topRight: Radius.circular(12), + topLeft: Radius.circular(12)), + boxShadow: [ + BoxShadow( + color: Color(0x17000000), spreadRadius: 0, blurRadius: 3), + ], + ), + child: ClipRRect( + borderRadius: BorderRadius.only( + topLeft: Radius.circular(12), + topRight: Radius.circular(12)), + child: BottomNavigationBar( + items: items, + elevation: 0, + backgroundColor: theme.isColorful + ? theme.mainColor + : theme.backgroundColor, + selectedItemColor: theme.isColorful + ? theme.textColorColorfulBackground + : theme.accentColor, + unselectedItemColor: theme.isColorful + ? theme.textColorColorfulBackground + : theme.mainColor, + showUnselectedLabels: true, + type: BottomNavigationBarType.fixed, + currentIndex: currentIndex, + onTap: (index) { + HapticFeedback.selectionClick(); + setState(() { + currentIndex = index; + pageController.jumpToPage(index); + }); + }, + ), ), ), - ), - ], + ], + ), ), ); } diff --git a/lib/widgets/standard_elements/frederic_scaffold.dart b/lib/widgets/standard_elements/frederic_scaffold.dart index 019b6f3..f2cebb2 100644 --- a/lib/widgets/standard_elements/frederic_scaffold.dart +++ b/lib/widgets/standard_elements/frederic_scaffold.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; import 'package:frederic/main.dart'; -import 'package:smooth_sheets/smooth_sheets.dart'; class FredericScaffold extends StatelessWidget { const FredericScaffold( @@ -18,18 +17,15 @@ class FredericScaffold extends StatelessWidget { @override Widget build(BuildContext context) { - return CupertinoStackedTransition( - cornerRadius: Tween(begin: 0.0, end: 16.0), - child: Scaffold( - floatingActionButton: floatingActionButton, - floatingActionButtonLocation: floatingActionButtonLocation, - backgroundColor: backgroundColor ?? - (theme.isColorful ? theme.mainColor : theme.backgroundColor), - body: SafeArea( - child: Container( - color: theme.backgroundColor, - child: body, - ), + return Scaffold( + floatingActionButton: floatingActionButton, + floatingActionButtonLocation: floatingActionButtonLocation, + backgroundColor: backgroundColor ?? + (theme.isColorful ? theme.mainColor : theme.backgroundColor), + body: SafeArea( + child: Container( + color: theme.backgroundColor, + child: body, ), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 6ab31f3..156d102 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -65,11 +65,7 @@ dependencies: infinite_listview: ^1.1.0 introduction_screen: ^3.1.12 cached_network_image: ^3.3.0 - - smooth_sheets: - git: - url: https://github.com/fujidaiti/smooth_sheets.git - path: package + cupertino_modal_sheet: ^1.1.0 sheet: git: