Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 39 additions & 24 deletions gallery/gallery/lib/studies/shrine/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ class _ShrineAppState extends State<ShrineApp> with TickerProviderStateMixin {
);
}

// Closes the bottom sheet if it is open.
Future<bool> _onWillPop() async {
final status = _expandingController.status;
if (status == AnimationStatus.completed ||
status == AnimationStatus.forward) {
_expandingController.reverse();
return false;
}

return true;
}

@override
Widget build(BuildContext context) {
final bool isDesktop = isDisplayDesktop(context);
Expand All @@ -86,34 +98,37 @@ class _ShrineAppState extends State<ShrineApp> with TickerProviderStateMixin {

return ScopedModel<AppStateModel>(
model: _model,
child: MaterialApp(
navigatorKey: widget.navigatorKey,
title: 'Shrine',
debugShowCheckedModeBanner: false,
home: LayoutCache(
layouts: _layouts,
child: PageStatus(
menuController: _controller,
cartController: _expandingController,
child: HomePage(
backdrop: backdrop,
scrim: Scrim(controller: _expandingController),
expandingBottomSheet: ExpandingBottomSheet(
hideController: _controller,
expandingController: _expandingController,
child: WillPopScope(
onWillPop: _onWillPop,
child: MaterialApp(
navigatorKey: widget.navigatorKey,
title: 'Shrine',
debugShowCheckedModeBanner: false,
home: LayoutCache(
layouts: _layouts,
child: PageStatus(
menuController: _controller,
cartController: _expandingController,
child: HomePage(
backdrop: backdrop,
scrim: Scrim(controller: _expandingController),
expandingBottomSheet: ExpandingBottomSheet(
hideController: _controller,
expandingController: _expandingController,
),
),
),
),
initialRoute: '/login',
onGenerateRoute: _getRoute,
theme: shrineTheme.copyWith(
platform: GalleryOptions.of(context).platform,
),
// L10n settings.
localizationsDelegates: GalleryLocalizations.localizationsDelegates,
supportedLocales: GalleryLocalizations.supportedLocales,
locale: GalleryOptions.of(context).locale,
),
initialRoute: '/login',
onGenerateRoute: _getRoute,
theme: shrineTheme.copyWith(
platform: GalleryOptions.of(context).platform,
),
// L10n settings.
localizationsDelegates: GalleryLocalizations.localizationsDelegates,
supportedLocales: GalleryLocalizations.supportedLocales,
locale: GalleryOptions.of(context).locale,
),
);
}
Expand Down
41 changes: 12 additions & 29 deletions gallery/gallery/lib/studies/shrine/expanding_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:scoped_model/scoped_model.dart';

Expand Down Expand Up @@ -51,11 +49,11 @@ double _paddedThumbnailHeight(BuildContext context) {
}

class ExpandingBottomSheet extends StatefulWidget {
const ExpandingBottomSheet(
{Key key,
@required this.hideController,
@required this.expandingController})
: assert(hideController != null),
const ExpandingBottomSheet({
Key key,
@required this.hideController,
@required this.expandingController,
}) : assert(hideController != null),
assert(expandingController != null),
super(key: key);

Expand Down Expand Up @@ -551,18 +549,6 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet>
}
}

// Closes the cart if the cart is open, otherwise exits the app (this should
// only be relevant for Android).
Future<bool> _onWillPop() async {
if (!_isOpen) {
await SystemNavigator.pop();
return true;
}

close();
return true;
}

@override
Widget build(BuildContext context) {
return AnimatedSize(
Expand All @@ -571,16 +557,13 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet>
curve: Curves.easeInOut,
vsync: this,
alignment: AlignmentDirectional.topStart,
child: WillPopScope(
onWillPop: _onWillPop,
child: AnimatedBuilder(
animation: widget.hideController,
builder: (context, child) => AnimatedBuilder(
animation: widget.expandingController,
builder: (context, child) => ScopedModelDescendant<AppStateModel>(
builder: (context, child, model) =>
_buildSlideAnimation(context, _buildCart(context)),
),
child: AnimatedBuilder(
animation: widget.hideController,
builder: (context, child) => AnimatedBuilder(
animation: widget.expandingController,
builder: (context, child) => ScopedModelDescendant<AppStateModel>(
builder: (context, child, model) =>
_buildSlideAnimation(context, _buildCart(context)),
),
),
),
Expand Down