Flutter 是否使用带有布线的抽屉,并检查当前活动的抽屉高光线路?
需要使用颤振抽屉的示例,使用菜单中突出显示当前路线的路线,并从任何其他路线返回主页路线,应用程序仅从主页退出这是我想到的:Flutter 是否使用带有布线的抽屉,并检查当前活动的抽屉高光线路?,flutter,Flutter,需要使用颤振抽屉的示例,使用菜单中突出显示当前路线的路线,并从任何其他路线返回主页路线,应用程序仅从主页退出这是我想到的: import 'package:myapp/blocs/provider.dart'; import 'package:myapp/routes.dart'; import 'package:flutter/material.dart'; class DrawerItemList extends StatelessWidget { String getCurrentR
import 'package:myapp/blocs/provider.dart';
import 'package:myapp/routes.dart';
import 'package:flutter/material.dart';
class DrawerItemList extends StatelessWidget {
String getCurrentRouteName(context) {
String currentRouteName;
Navigator.popUntil(context, (route) {
currentRouteName = route.settings.name;
return true;
});
return currentRouteName;
}
@override
Widget build(BuildContext context) {
final bloc = Provider.of(context);
String currentRoute = getCurrentRouteName(context);
return Column(
children: <Widget>[
AppBar(
automaticallyImplyLeading: false,
title: Text('MyAppTitle'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.exit_to_app),
tooltip: 'Log Out',
onPressed: () {
bloc.logOut();
Navigator.pushReplacementNamed(
context,
AppRoutes.home,
);
},
),
],
),
ListTile(
leading: Icon(Icons.home),
title: Text('Home'),
selected: currentRoute == AppRoutes.home,
onTap: () {
if (currentRoute == AppRoutes.home) return;
Navigator.pushReplacementNamed(
context,
AppRoutes.home,
);
},
),
ListTile(
leading: Icon(Icons.list),
title: Text('Records'),
selected: currentRoute == AppRoutes.records,
onTap: () {
if (currentRoute == AppRoutes.records) return;
Navigator.pushReplacementNamed(
context,
AppRoutes.records,
);
},
),
ListTile(
title: Text('Planning'),
leading: Icon(Icons.graphic_eq),
selected: currentRoute == AppRoutes.planning,
onTap: () {
if (currentRoute == AppRoutes.planning) return;
Navigator.pushReplacementNamed(
context,
AppRoutes.planning,
);
},
),
],
);
}
}
import'包:myapp/blocs/provider.dart';
导入“包:myapp/routes.dart”;
进口“包装:颤振/材料.省道”;
类DrawerItemList扩展了无状态小部件{
字符串getCurrentRouteName(上下文){
字符串currentRouteName;
Navigator.popintil(上下文,(路由){
currentRouteName=route.settings.name;
返回true;
});
返回当前路由名称;
}
@凌驾
小部件构建(构建上下文){
final bloc=Provider.of(上下文);
字符串currentRoute=getCurrentRouteName(上下文);
返回列(
儿童:[
AppBar(
自动嵌入:false,
标题:文本(“MyAppTitle”),
行动:[
图标按钮(
图标:图标(图标。退出到应用程序),
工具提示:“注销”,
已按下:(){
bloc.logOut();
Navigator.pushReplacementNamed(
上下文
批准,
);
},
),
],
),
列表砖(
前导:图标(Icons.home),
标题:文本(“主页”),
所选:currentRoute==AppRoutes.home,
onTap:(){
if(currentRoute==AppRoutes.home)返回;
Navigator.pushReplacementNamed(
上下文
批准,
);
},
),
列表砖(
前导:图标(Icons.list),
标题:文本(“记录”),
选中:currentRoute==AppRoutes.records,
onTap:(){
if(currentRoute==AppRoutes.records)返回;
Navigator.pushReplacementNamed(
上下文
批准记录,
);
},
),
列表砖(
标题:文本(“规划”),
前导:图标(图标、图形),
所选:currentRoute==AppRoutes.planning,
onTap:(){
if(currentRoute==AppRoutes.planning)返回;
Navigator.pushReplacementNamed(
上下文
批准、规划、,
);
},
),
],
);
}
}