Created
April 1, 2022 01:54
-
-
Save sachindayl/10ad18f5404ee6f61145b3f559f8181c to your computer and use it in GitHub Desktop.
[Cupertino View Scaffold] #flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:app/cupertino/widgets/custom_cupertino_circular_progress_indicator.dart'; | |
| import 'package:app/shared/base/constants/constants.dart'; | |
| import 'package:app/shared/models/enums.dart'; | |
| import 'package:flutter/cupertino.dart'; | |
| class BaseViewScaffold extends StatelessWidget { | |
| final bool isSliverNavigation; | |
| final Widget? navigationBar; | |
| final String pageTitle; | |
| final List<Widget> slivers; | |
| final Widget? leading; | |
| final Widget? trailing; | |
| final bool isTopSafe; | |
| final bool isBottomSafe; | |
| final LoadingState isLoading; | |
| final ScrollPhysics? physics; | |
| final Future<void> Function()? onRefresh; | |
| final Future<bool>Function()? onBackPressed; | |
| const BaseViewScaffold( | |
| {Key? key, | |
| this.isSliverNavigation = false, | |
| this.navigationBar, | |
| required this.pageTitle, | |
| required this.slivers, | |
| this.leading, | |
| this.trailing, | |
| this.isTopSafe = true, | |
| this.isBottomSafe = true, | |
| this.isLoading = LoadingState.initial, | |
| this.physics, | |
| this.onRefresh, | |
| this.onBackPressed | |
| }) | |
| : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return WillPopScope( | |
| onWillPop: onBackPressed, | |
| child: CupertinoPageScaffold( | |
| navigationBar: !isSliverNavigation && pageTitle != Constants.emptyString | |
| ? CupertinoNavigationBar( | |
| brightness: Brightness.light, | |
| leading: leading, | |
| middle: Text(pageTitle), | |
| trailing: trailing, | |
| ) | |
| : null, | |
| child: SafeArea( | |
| top: isTopSafe, | |
| bottom: isBottomSafe, | |
| child: isLoading == LoadingState.loading | |
| ? const Center(child: CupertinoCircularProgressIndicator()) | |
| : CustomScrollView( | |
| physics: physics, | |
| slivers: _getSlivers(), | |
| ), | |
| )), | |
| ); | |
| } | |
| List<Widget> _getSlivers() { | |
| List<Widget> navigationSliver = [ | |
| SliverVisibility( | |
| visible: onRefresh != null, | |
| sliver: CupertinoSliverRefreshControl(onRefresh: onRefresh)), | |
| SliverVisibility( | |
| visible: isSliverNavigation, | |
| sliver: CupertinoSliverNavigationBar( | |
| largeTitle: Text(pageTitle), | |
| trailing: trailing, | |
| )), | |
| ]; | |
| return navigationSliver + slivers; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment