import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:fun_selfie_app/utils/storage.dart'; import 'package:fun_selfie_app/utils/common_toast.dart'; class DrawerModalPage extends StatefulWidget { const DrawerModalPage({Key? key}) : super(key: key); @override State createState() => _DrawerModalPageState(); } class _DrawerModalPageState extends State { late Map userMsgObj = {'configName': '', 'configPass': ''}; @override void initState() { super.initState(); // 初始化的时候开启倒计时 getUser(context); } @override Widget build(BuildContext context) { final screenSize = MediaQuery.of(context).size; return Drawer( // elevation: 16.0, child: Stack( children: [ Container( height: screenSize.height / 2, color: const Color(0xff009EBA), padding: const EdgeInsetsDirectional.only(top: 80), alignment: Alignment.center, child: Column( children: [ const ClipOval( child: Image( image: AssetImage('static/images/login_bg.png'), fit: BoxFit.fill, width: 200, height: 200, ), ), const SizedBox(height: 30), Text( '${userMsgObj['configName']}', style: const TextStyle(fontSize: 30, color: Colors.white), ), Text( '${userMsgObj['configPass']}', style: const TextStyle(fontSize: 16, color: Colors.white), ), ], )), Positioned( bottom: 20, right: 16, left: 16, child: SizedBox( height: 50, child: ElevatedButton( child: const Text( "退出", style: TextStyle(fontSize: 18), ), onPressed: () async { Navigator.pop(context); Navigator.pushNamed(context, "/login"); CommonToast.okToast('已经退出登录'); await StorageUtil.remove('userMsg'); }, ))) ], )); } void getUser(context) async { String userMsg = await StorageUtil.getString('userMsg'); if (userMsg.isNotEmpty) { setState(() { userMsgObj = jsonDecode(userMsg); }); } else { Navigator.pushNamed(context, "/login"); } } }