drawer.dart 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import 'package:ctjt_flutter/common/states.dart';
  2. import 'package:ctjt_flutter/common/styles.dart';
  3. import 'package:ctjt_flutter/common/utils.dart';
  4. import 'package:flutter/gestures.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_screenutil/flutter_screenutil.dart';
  7. import 'package:provider/provider.dart';
  8. /* ----------------------------------左侧抽屉--------------------------------- */
  9. class DrawerMenu extends StatelessWidget {
  10. String getUserShowName(BuildContext context) {
  11. String userName = Provider.of<UserStatus>(context, listen: false).userName;
  12. if (null == userName || userName.isEmpty) {
  13. return "";
  14. }
  15. userName = userName.trim();
  16. if (Utils.testCellNo(userName)) {
  17. userName = userName.substring(0, 3) + '****' + userName.substring(7);
  18. }
  19. return userName;
  20. }
  21. @override
  22. Widget build(BuildContext context) {
  23. return SizedBox(
  24. width: 812.0.w,
  25. child: Drawer(
  26. child: Column(
  27. children: <Widget>[
  28. // 头部
  29. Container(
  30. width: double.infinity,
  31. height: 355.h,
  32. padding: EdgeInsets.fromLTRB(70.0.w,
  33. 102.0.h, 0, 0),
  34. child: Column(
  35. crossAxisAlignment: CrossAxisAlignment.start,
  36. children: [
  37. Text("Test",
  38. style: TextStyle(
  39. fontSize: 72.0.w,
  40. fontWeight: FontWeight.normal,
  41. color: Styles.primaryColor)),
  42. Padding(
  43. padding: EdgeInsets.only(top: 30.h),
  44. ),
  45. Text(Provider.of<UserStatus>(context).userName.isEmpty ? '用户未登录' : '用户:' + getUserShowName(context),
  46. style: TextStyle(
  47. fontSize: 36.0.w,
  48. fontWeight: FontWeight.normal,
  49. color: Styles.primaryColor)),
  50. ],
  51. ),
  52. decoration: BoxDecoration(color: Colors.white, boxShadow: [
  53. BoxShadow(
  54. color: Colors.black12,
  55. offset: Offset(0.0, 0.0), //阴影xy轴偏移量
  56. blurRadius: ScreenUtil().radius(16), //阴影模糊程度
  57. spreadRadius: ScreenUtil().radius(2) //阴影扩散程度
  58. )
  59. ]),
  60. ),
  61. Padding(
  62. padding:
  63. EdgeInsets.fromLTRB(0, 35.0.h, 0, 0),
  64. ),
  65. ListTile(
  66. contentPadding: Styles.drawerTilePadding,
  67. title: Text("关于", style: Styles.drawerTileStyle),
  68. onTap: () {
  69. Utils.vibrate();
  70. Navigator.of(context).pop(); // 隐藏侧边栏
  71. Navigator.pushNamed(context, '/about');
  72. },
  73. ),
  74. Expanded( // 占满剩余空间
  75. child: Offstage(
  76. offstage: Provider.of<AppVersion>(context).appVersion.isEmpty,
  77. child: Container(
  78. alignment: Alignment.bottomLeft,
  79. padding: EdgeInsets.fromLTRB(
  80. 70.0.w,
  81. 0,
  82. 70.0.w,
  83. 170.0.h),
  84. child: Text('应用版本 ' + Provider.of<AppVersion>(context).appVersion,
  85. style: TextStyle(
  86. fontSize: 36.0.sp,
  87. fontWeight: FontWeight.normal,
  88. color: Colors.grey)),
  89. ),
  90. )
  91. ),
  92. ],
  93. ),
  94. ),
  95. );
  96. }
  97. }