我想如果gettoken是空显示登录页面,但gettoken不是空显示配置文件页面(对不起我的英语)。现在我没有个人资料页,所以我把空。我用列表来显示页面,但我不知道没有列表。我想要这个设计。因为这就是他想从我这里得到的。我对cacheManager.gettoken使用了sharedpreference
import 'dart:io';
import 'package:animated_bottom_navigation_bar/animated_bottom_navigation_bar.dart';
import 'package:est/view/auth/view/login_view.dart';
import 'package:flutter/material.dart';
import '../../empty_page.dart';
import '../../product/constant/app_color.dart';
import '../../product/constant/app_text.dart';
import '../../product/user_check/cache_manager.dart';
import '../appo/view/appo_view.dart';
import '../home/Home.dart';
class DashBoardView extends StatefulWidget {
const DashBoardView({super.key});
@override
State<DashBoardView> createState() => _DashBoardViewState();
}
class _DashBoardViewState extends State<DashBoardView> {
CacheManager cacheManager = CacheManager();
int _bottomNavIndex = 0;
final List<IconData> _iconList = [Icons.home, Icons.person, Icons.local_hospital, Icons.car_crash];
final pageList = [const Home(), const AppoView(), const Empty(),`this is error "cachemanager"`cacheManager.getToken()=="" ?const Empty():LoginView()];
@override
Widget build(BuildContext context) {
bool showFab = MediaQuery.of(context).viewInsets.bottom != 0;
return WillPopScope(
onWillPop: () async {
final value = await showDialog<bool>(
context: context,
builder: (context) {
return _willPopScopeDialog(context);
});
if (value != null) {
if (value == true) {
exit(0);
}
}
return false;
},
child: Scaffold(
extendBody: true,
body: pageList[_bottomNavIndex],
floatingActionButton: Visibility(
visible: !showFab,
child: FloatingActionButton(
child: const Text(
"+",
style: TextStyle(fontSize: 55),
),
onPressed: () {
showDialog(
context: context,
builder: (context) {
return Padding(
padding: const EdgeInsets.only(bottom: 100),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [_floatingButton(myproc, const Empty()), _floatingButton(online, const Empty())]),
);
},
);
}),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: AnimatedBottomNavigationBar(
inactiveColor: Colors.grey,
activeColor: primaryColor1,
gapLocation: GapLocation.center,
icons: _iconList,
notchSmoothness: NotchSmoothness.softEdge,
activeIndex: _bottomNavIndex,
onTap: (index) {
setState(() {
_bottomNavIndex = index;
});
},
),
),
);
}
TextButton _floatingButton(String text, Widget pushpage) {
return TextButton.icon(
style: const ButtonStyle(backgroundColor: MaterialStatePropertyAll<Color>(Colors.white)),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => pushpage,
));
},
icon: const Icon(Icons.home, color: primaryColor1),
label: Text(
text,
style: const TextStyle(fontFamily: poppins, color: Colors.black, fontSize: 18),
));
}
}
AlertDialog _willPopScopeDialog(BuildContext context) {
return AlertDialog(
content: const Text(leave, style: TextStyle(fontFamily: poppins)),
actions: [
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: primaryColor1),
onPressed: () => Navigator.of(context).pop(true),
child: const Text(yes, style: TextStyle(fontFamily: poppins))),
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: primaryColor1),
onPressed: () => Navigator.of(context).pop(false),
child: const Text(no, style: TextStyle(fontFamily: poppins)))
],
);
}
这是因为您在final
成员中使用了带有测试的条件。因此,您应该拥有带有late
修饰符的变量。
late pageList = [const Home(), const AppoView(), const Empty(),cacheManager.getToken()=="" ?const Empty():LoginView()];
或
late pageList = [];
@override
void initState() {
super.initState();
pageList = [const Home(), const AppoView(), const Empty(),cacheManager.getToken()=="" ?const Empty():LoginView()];
}