import 'package:ctjt_flutter/common/states.dart'; import 'package:ctjt_flutter/common/styles.dart'; import 'package:ctjt_flutter/common/utils.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:provider/provider.dart'; /* ----------------------------------左侧抽屉--------------------------------- */ class DrawerMenu extends StatelessWidget { String getUserShowName(BuildContext context) { String userName = Provider.of(context, listen: false).userName; if (null == userName || userName.isEmpty) { return ""; } userName = userName.trim(); if (Utils.testCellNo(userName)) { userName = userName.substring(0, 3) + '****' + userName.substring(7); } return userName; } @override Widget build(BuildContext context) { return SizedBox( width: 812.0.w, child: Drawer( child: Column( children: [ // 头部 Container( width: double.infinity, height: 355.h, padding: EdgeInsets.fromLTRB(70.0.w, 102.0.h, 0, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text("Test", style: TextStyle( fontSize: 72.0.w, fontWeight: FontWeight.normal, color: Styles.primaryColor)), Padding( padding: EdgeInsets.only(top: 30.h), ), Text(Provider.of(context).userName.isEmpty ? '用户未登录' : '用户:' + getUserShowName(context), style: TextStyle( fontSize: 36.0.w, fontWeight: FontWeight.normal, color: Styles.primaryColor)), ], ), decoration: BoxDecoration(color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black12, offset: Offset(0.0, 0.0), //阴影xy轴偏移量 blurRadius: ScreenUtil().radius(16), //阴影模糊程度 spreadRadius: ScreenUtil().radius(2) //阴影扩散程度 ) ]), ), Padding( padding: EdgeInsets.fromLTRB(0, 35.0.h, 0, 0), ), ListTile( contentPadding: Styles.drawerTilePadding, title: Text("关于", style: Styles.drawerTileStyle), onTap: () { Utils.vibrate(); Navigator.of(context).pop(); // 隐藏侧边栏 Navigator.pushNamed(context, '/about'); }, ), Expanded( // 占满剩余空间 child: Offstage( offstage: Provider.of(context).appVersion.isEmpty, child: Container( alignment: Alignment.bottomLeft, padding: EdgeInsets.fromLTRB( 70.0.w, 0, 70.0.w, 170.0.h), child: Text('应用版本 ' + Provider.of(context).appVersion, style: TextStyle( fontSize: 36.0.sp, fontWeight: FontWeight.normal, color: Colors.grey)), ), ) ), ], ), ), ); } }