问题描述
我有一个包含许多菜单项的抽屉小部件。我有一个变量来处理选定的项目编号。我用 1 启动它来选择加载的第一个项目。当我选择另一个 MenuItem 时,该值会更改为相应的项目编号。当我从 Menuitem 页面重定向/重新路由到抽屉页面时,它再次显示第一个 Menuitem。我希望变量值保留并显示我选择的菜单项。
import 'package:country_code_picker/country_localizations.dart';
import 'package:Flutter/material.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:wyiin_admin_portal/admin_screens/access_management.dart';
import 'package:wyiin_admin_portal/admin_screens/brand_management_main.dart';
import 'package:wyiin_admin_portal/admin_screens/language_management_main.dart';
import 'package:wyiin_admin_portal/admin_screens/product_category_management_main.dart';
import 'package:wyiin_admin_portal/admin_screens/promotion_management_main.dart';
import 'package:wyiin_admin_portal/login/password_reset.dart';
import 'package:wyiin_admin_portal/model/BrandMgmtScreens.dart';
import 'package:wyiin_admin_portal/work_in_progress.dart';
class MyAppDrawer extends StatelessWidget {
final appTitle = 'WYIIN';
@override
Widget build(BuildContext context) {
return MaterialApp(
supportedLocales: [
const Locale('en','US'),],debugShowCheckedModeBanner: false,localizationsDelegates: [CountryLocalizations.delegate],title: appTitle,home: MyDrawer(title: appTitle),theme: ThemeData(primaryColor: Color.fromrGBO(255,255,1)),);
}
}
class MyDrawer extends StatefulWidget {
final String title;
final int destination;
MyDrawer({Key key,this.title,this.destination}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyDrawer> {
var _selectedDestination;
@override
Widget build(BuildContext context) {
print(_selectedDestination);
setState(() {
_selectedDestination =
_selectedDestination == null ? 1 : _selectedDestination;
});
print(_selectedDestination);
return ScopedModelDescendant<Screen>(builder: (_,child,model) {
return Row(
children: [
Container(
width: 255,child: Drawer(
child: Container(
color: Color.fromrGBO(42,48,66,1),child: ListView(
padding: EdgeInsets.zero,children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),child: Text('WYiiN',style: TextStyle(
fontSize: 18,fontWeight: FontWeight.bold,color: Colors.white)),),Padding(
padding: const EdgeInsets.only(left: 15,top: 4),child: Text('Menu',style: TextStyle(
fontSize: 14,fontWeight: FontWeight.w600,color: Color.fromrGBO(106,113,135,1))),ListTile(
visualDensity: VisualDensity(horizontal: -4,vertical: 0),contentPadding: const EdgeInsets.only(left: 15,leading: _selectedDestination == 6
? Image.asset(
'assets/images/Brand Management_active.png')
: Image.asset('assets/images/Brand Management.png'),title: Text('Brand management',style: TextStyle(
fontSize: 13,fontWeight: FontWeight.w300,color: _selectedDestination == 6
? Colors.white
: Color.fromrGBO(106,)),selected: _selectedDestination == 6,onTap: () {
if (model.showScreen == true) {
model.screenDecide();
}
selectDestination(6);
},ListTile(
visualDensity:
VisualDensity(horizontal: -4,leading: _selectedDestination == 8
? Image.asset(
'assets/images/product_category_management_active.png')
: Image.asset(
'assets/images/product_category_management.png'),title: Text('Product Category management',style: TextStyle(
fontSize: 13,color: _selectedDestination == 8
? Colors.white
: Color.fromrGBO(106,selected: _selectedDestination == 8,onTap: () {
if (model.showProdCatScreen == true) {
model.screenDecideProdCat();
}
selectDestination(8);
}),leading: _selectedDestination == 9
? Image.asset(
'assets/images/language_management_active.png')
: Image.asset(
'assets/images/language_management.png'),title: Text('Language Management',color: _selectedDestination == 9
? Colors.white
: Color.fromrGBO(106,selected: _selectedDestination == 9,onTap: () {
if (model.showLangMgmtScreen == true) {
model.screenDecideLangMgmt();
}
selectDestination(9);
}),VerticalDivider(
width: 1,thickness: 1,Expanded(
child: Scaffold(
body: _selectedDestination == 6
? BrandMgmtMain()
: _selectedDestination == 9
? LanguageMgmtMain()
: _selectedDestination == 7
? AccessMgmt()
: _selectedDestination == 8
? ProdCatMgmtMain()
: _selectedDestination == 5
? PromotionMgmtMain()
: _selectedDestination == 2
? WorkInProgress()
: _selectedDestination == 10
? PassReset()
: _selectedDestination == 1
? WorkInProgress()
: WorkInProgress()),);
});
}
void selectDestination(int index) {
setState(() {
_selectedDestination = index;
print(_selectedDestination);
});
}
}
void body(int selection) {}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)