您正在做的事情听起来有点像a
BottomNavigationBar,所以您可能需要考虑其中一种而不是a
Drawer。
但是,只有一个
Scaffold并更新
body用户点击抽屉项目时的时间是完全合理的方法。您可能会考虑
FadeTransition从一个身体变为另一个身体。
或者,如果您喜欢使用
Navigator但不希望使用默认的幻灯片动画,则可以通过扩展来自定义(或禁用)动画
MaterialPageRoute。这是一个例子:
import 'package:flutter/material.dart';void main() { runApp(new MyApp());}class MyCustomRoute<T> extends MaterialPageRoute<T> { MyCustomRoute({ WidgetBuilder builder, RouteSettings settings }) : super(builder: builder, settings: settings); @override Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) { if (settings.isInitialRoute) return child; // Fades between routes. (If you don't want any animation, // just return child.) return new FadeTransition(opacity: animation, child: child); }}class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Navigation example', onGenerateRoute: (RouteSettings settings) { switch (settings.name) { case '/': return new MyCustomRoute( builder: (_) => new MyHomePage(), settings: settings, ); case '/somewhere': return new MyCustomRoute( builder: (_) => new Somewhere(), settings: settings, ); } assert(false); } ); }}class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text('Navigation example'), ), drawer: new Drawer( child: new ListView( children: <Widget> [ new DrawerHeader( child: new Container( child: const Text('This is a header'), ), ), new ListTile( leading: const Icon(Icons.navigate_next), title: const Text('Navigate somewhere'), onTap: () { Navigator.pushNamed(context, '/somewhere'); }, ), ], ), ), body: new Center( child: new Text( 'This is a home page.', ), ), ); }}class Somewhere extends StatelessWidget { Widget build(BuildContext context) { return new Scaffold( body: new Center( child: new Text( 'Congrats, you did it.', ), ), appBar: new AppBar( title: new Text('Somewhere'), ), drawer: new Drawer( child: new ListView( children: <Widget>[ new DrawerHeader( child: new Container( child: const Text('This is a header'), ), ), ], ), ), ); }}


