Unverified Commit 9db8966f authored by xster's avatar xster Committed by GitHub

Make drawer demo header not scroll away (#13337)

* Make drawer demo header not scroll

* Add test for gallery drawer demo and fix user accounts drawer header overflow
parent 3280f234
...@@ -276,12 +276,18 @@ ...@@ -276,12 +276,18 @@
inputPaths = ( inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh", "${SRCROOT}/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../../../../bin/cache/artifacts/engine/ios/Flutter.framework", "${PODS_ROOT}/../../../../bin/cache/artifacts/engine/ios/Flutter.framework",
"${BUILT_PRODUCTS_DIR}/Reachability/Reachability.framework",
"${BUILT_PRODUCTS_DIR}/connectivity/connectivity.framework",
"${BUILT_PRODUCTS_DIR}/url_launcher/url_launcher.framework", "${BUILT_PRODUCTS_DIR}/url_launcher/url_launcher.framework",
"${BUILT_PRODUCTS_DIR}/video_player/video_player.framework",
); );
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputPaths = ( outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/connectivity.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/url_launcher.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/video_player.framework",
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh; shellPath = /bin/sh;
...@@ -508,4 +514,4 @@ ...@@ -508,4 +514,4 @@
/* End XCConfigurationList section */ /* End XCConfigurationList section */
}; };
rootObject = 97C146E61CF9000F007C117D /* Project object */; rootObject = 97C146E61CF9000F007C117D /* Project object */;
} }
\ No newline at end of file
...@@ -89,7 +89,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -89,7 +89,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
title: const Text('Navigation drawer'), title: const Text('Navigation drawer'),
), ),
drawer: new Drawer( drawer: new Drawer(
child: new ListView( child: new Column(
children: <Widget>[ children: <Widget>[
new UserAccountsDrawerHeader( new UserAccountsDrawerHeader(
accountName: const Text('Zach Widget'), accountName: const Text('Zach Widget'),
...@@ -114,6 +114,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -114,6 +114,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
), ),
), ),
], ],
margin: EdgeInsets.zero,
onDetailsPressed: () { onDetailsPressed: () {
_showDrawerContents = !_showDrawerContents; _showDrawerContents = !_showDrawerContents;
if (_showDrawerContents) if (_showDrawerContents)
...@@ -122,48 +123,58 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin { ...@@ -122,48 +123,58 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
_controller.forward(); _controller.forward();
}, },
), ),
new ClipRect( new MediaQuery.removePadding(
child: new Stack( context: context,
children: <Widget>[ // DrawerHeader consumes top MediaQuery padding.
// The initial contents of the drawer. removeTop: true,
new FadeTransition( child: new Expanded(
opacity: _drawerContentsOpacity, child: new ListView(
child: new Column( padding: const EdgeInsets.only(top: 8.0),
mainAxisSize: MainAxisSize.min, children: <Widget>[
crossAxisAlignment: CrossAxisAlignment.stretch, new Stack(
children: _drawerContents.map((String id) { children: <Widget>[
return new ListTile( // The initial contents of the drawer.
leading: new CircleAvatar(child: new Text(id)), new FadeTransition(
title: new Text('Drawer item $id'), opacity: _drawerContentsOpacity,
onTap: _showNotImplementedMessage, child: new Column(
); mainAxisSize: MainAxisSize.min,
}).toList(), crossAxisAlignment: CrossAxisAlignment.stretch,
), children: _drawerContents.map((String id) {
), return new ListTile(
// The drawer's "details" view. leading: new CircleAvatar(child: new Text(id)),
new SlideTransition( title: new Text('Drawer item $id'),
position: _drawerDetailsPosition, onTap: _showNotImplementedMessage,
child: new FadeTransition( );
opacity: new ReverseAnimation(_drawerContentsOpacity), }).toList(),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new ListTile(
leading: const Icon(Icons.add),
title: const Text('Add account'),
onTap: _showNotImplementedMessage,
), ),
new ListTile( ),
leading: const Icon(Icons.settings), // The drawer's "details" view.
title: const Text('Manage accounts'), new SlideTransition(
onTap: _showNotImplementedMessage, position: _drawerDetailsPosition,
child: new FadeTransition(
opacity: new ReverseAnimation(_drawerContentsOpacity),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
new ListTile(
leading: const Icon(Icons.add),
title: const Text('Add account'),
onTap: _showNotImplementedMessage,
),
new ListTile(
leading: const Icon(Icons.settings),
title: const Text('Manage accounts'),
onTap: _showNotImplementedMessage,
),
],
),
), ),
], ),
), ],
), ),
), ],
], ),
), ),
), ),
], ],
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_gallery/demo/material/drawer_demo.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Drawer header does not scroll', (WidgetTester tester) async {
await tester.pumpWidget(new MaterialApp(
theme: new ThemeData(platform: TargetPlatform.iOS),
home: new DrawerDemo(),
));
await tester.tap(find.text('Tap here to open the drawer'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(tester.getTopLeft(find.byType(UserAccountsDrawerHeader)).dy, 0.0);
final double initialTopItemSaneY = tester.getTopLeft(find.text('Drawer item A')).dy;
expect(initialTopItemSaneY, greaterThan(0.0));
await tester.drag(find.text('Drawer item B'), const Offset(0.0, 400.0));
await tester.pump();
expect(tester.getTopLeft(find.byType(UserAccountsDrawerHeader)).dy, 0.0);
expect(tester.getTopLeft(find.text('Drawer item A')).dy, greaterThan(initialTopItemSaneY));
expect(tester.getTopLeft(find.text('Drawer item A')).dy, lessThanOrEqualTo(initialTopItemSaneY + 400.0));
});
}
...@@ -68,18 +68,18 @@ class _AccountDetails extends StatelessWidget { ...@@ -68,18 +68,18 @@ class _AccountDetails extends StatelessWidget {
final bool isOpen; final bool isOpen;
Widget addDropdownIcon(Widget line) { Widget addDropdownIcon(Widget line) {
final Widget icon = new Expanded( final Widget icon = new Icon(
child: new Align( isOpen ? Icons.arrow_drop_up : Icons.arrow_drop_down,
alignment: AlignmentDirectional.centerEnd, color: Colors.white
child: new Icon(
isOpen ? Icons.arrow_drop_up : Icons.arrow_drop_down,
color: Colors.white
),
),
); );
return new Row( return new Expanded(
crossAxisAlignment: CrossAxisAlignment.center, child: new Row(
children: line == null ? <Widget>[icon] : <Widget>[line, icon], crossAxisAlignment: CrossAxisAlignment.center,
children: line == null ? <Widget>[icon] : <Widget>[
new Expanded(child: line),
icon,
],
),
); );
} }
...@@ -88,10 +88,12 @@ class _AccountDetails extends StatelessWidget { ...@@ -88,10 +88,12 @@ class _AccountDetails extends StatelessWidget {
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
Widget accountNameLine = accountName == null ? null : new DefaultTextStyle( Widget accountNameLine = accountName == null ? null : new DefaultTextStyle(
style: theme.primaryTextTheme.body2, style: theme.primaryTextTheme.body2,
overflow: TextOverflow.ellipsis,
child: accountName, child: accountName,
); );
Widget accountEmailLine = accountEmail == null ? null : new DefaultTextStyle( Widget accountEmailLine = accountEmail == null ? null : new DefaultTextStyle(
style: theme.primaryTextTheme.body1, style: theme.primaryTextTheme.body1,
overflow: TextOverflow.ellipsis,
child: accountEmail, child: accountEmail,
); );
if (onTap != null) { if (onTap != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment