setting.dart 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:fun_selfie_app/utils/storage.dart';
  4. import 'package:fun_selfie_app/utils/common_toast.dart';
  5. class DrawerModalPage extends StatefulWidget {
  6. const DrawerModalPage({Key? key}) : super(key: key);
  7. @override
  8. State<StatefulWidget> createState() => _DrawerModalPageState();
  9. }
  10. class _DrawerModalPageState extends State<DrawerModalPage> {
  11. late Map userMsgObj = {'configName': '', 'configPass': ''};
  12. @override
  13. void initState() {
  14. super.initState();
  15. // 初始化的时候开启倒计时
  16. getUser(context);
  17. }
  18. @override
  19. Widget build(BuildContext context) {
  20. final screenSize = MediaQuery.of(context).size;
  21. return Drawer(
  22. // elevation: 16.0,
  23. child: Stack(
  24. children: <Widget>[
  25. Container(
  26. height: screenSize.height / 2,
  27. color: const Color(0xff009EBA),
  28. padding: const EdgeInsetsDirectional.only(top: 60),
  29. alignment: Alignment.center,
  30. child: Column(
  31. children: <Widget>[
  32. const ClipOval(
  33. child: Image(
  34. image: AssetImage('static/images/login_bg.png'),
  35. fit: BoxFit.fill,
  36. width: 300,
  37. height: 300,
  38. ),
  39. ),
  40. const SizedBox(height: 30),
  41. Text(
  42. '${userMsgObj['configName']}',
  43. style: const TextStyle(fontSize: 30, color: Colors.white),
  44. ),
  45. Text(
  46. '${userMsgObj['configPass']}',
  47. style: const TextStyle(fontSize: 16, color: Colors.white),
  48. ),
  49. ],
  50. )),
  51. Positioned(
  52. bottom: 20,
  53. right: 16,
  54. left: 16,
  55. child: SizedBox(
  56. height: 50,
  57. child: ElevatedButton(
  58. child: const Text(
  59. "退出",
  60. style: TextStyle(fontSize: 18),
  61. ),
  62. onPressed: () async {
  63. Navigator.pop(context);
  64. Navigator.pushNamed(context, "/login");
  65. CommonToast.okToast('已经退出登录');
  66. await StorageUtil.remove('userMsg');
  67. },
  68. )))
  69. ],
  70. ));
  71. }
  72. void getUser(context) async {
  73. String userMsg = await StorageUtil.getString('userMsg');
  74. if (userMsg.isNotEmpty) {
  75. setState(() {
  76. userMsgObj = jsonDecode(userMsg);
  77. });
  78. } else {
  79. Navigator.pushNamed(context, "/login");
  80. }
  81. }
  82. }