33// found in the LICENSE file.
44
55import 'package:flutter/material.dart' ;
6+ import 'package:flutter/services.dart' ;
67import 'package:gallery/data/gallery_options.dart' ;
78import 'package:gallery/l10n/gallery_localizations.dart' ;
89import 'package:gallery/layout/adaptive.dart' ;
@@ -78,6 +79,18 @@ class _ShrineAppState extends State<ShrineApp> with TickerProviderStateMixin {
7879 );
7980 }
8081
82+ // Closes the bottom sheet if it is open (this should only be relevant for Android).
83+ Future <bool > _onWillPop () async {
84+ final AnimationStatus status = _expandingController.status;
85+ if (status == AnimationStatus .completed ||
86+ status == AnimationStatus .forward) {
87+ _expandingController.reverse ();
88+ return false ;
89+ }
90+
91+ return true ;
92+ }
93+
8194 @override
8295 Widget build (BuildContext context) {
8396 final bool isDesktop = isDisplayDesktop (context);
@@ -86,34 +99,37 @@ class _ShrineAppState extends State<ShrineApp> with TickerProviderStateMixin {
8699
87100 return ScopedModel <AppStateModel >(
88101 model: _model,
89- child: MaterialApp (
90- navigatorKey: widget.navigatorKey,
91- title: 'Shrine' ,
92- debugShowCheckedModeBanner: false ,
93- home: LayoutCache (
94- layouts: _layouts,
95- child: PageStatus (
96- menuController: _controller,
97- cartController: _expandingController,
98- child: HomePage (
99- backdrop: backdrop,
100- scrim: Scrim (controller: _expandingController),
101- expandingBottomSheet: ExpandingBottomSheet (
102- hideController: _controller,
103- expandingController: _expandingController,
102+ child: WillPopScope (
103+ onWillPop: _onWillPop,
104+ child: MaterialApp (
105+ navigatorKey: widget.navigatorKey,
106+ title: 'Shrine' ,
107+ debugShowCheckedModeBanner: false ,
108+ home: LayoutCache (
109+ layouts: _layouts,
110+ child: PageStatus (
111+ menuController: _controller,
112+ cartController: _expandingController,
113+ child: HomePage (
114+ backdrop: backdrop,
115+ scrim: Scrim (controller: _expandingController),
116+ expandingBottomSheet: ExpandingBottomSheet (
117+ hideController: _controller,
118+ expandingController: _expandingController,
119+ ),
104120 ),
105121 ),
106122 ),
123+ initialRoute: '/login' ,
124+ onGenerateRoute: _getRoute,
125+ theme: shrineTheme.copyWith (
126+ platform: GalleryOptions .of (context).platform,
127+ ),
128+ // L10n settings.
129+ localizationsDelegates: GalleryLocalizations .localizationsDelegates,
130+ supportedLocales: GalleryLocalizations .supportedLocales,
131+ locale: GalleryOptions .of (context).locale,
107132 ),
108- initialRoute: '/login' ,
109- onGenerateRoute: _getRoute,
110- theme: shrineTheme.copyWith (
111- platform: GalleryOptions .of (context).platform,
112- ),
113- // L10n settings.
114- localizationsDelegates: GalleryLocalizations .localizationsDelegates,
115- supportedLocales: GalleryLocalizations .supportedLocales,
116- locale: GalleryOptions .of (context).locale,
117133 ),
118134 );
119135 }
0 commit comments