diff --git a/lib/pages/mine/view.dart b/lib/pages/mine/view.dart index bad04fec..8072206d 100644 --- a/lib/pages/mine/view.dart +++ b/lib/pages/mine/view.dart @@ -35,231 +35,259 @@ class _MinePageState extends State { }); } + Widget get _header => FittedBox( + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const SizedBox(width: 12), + Image.asset( + 'assets/images/logo/logo_android_2.png', + width: 35, + ), + const SizedBox(width: 5), + Text( + 'PiliPalaX', + style: Theme.of(context).textTheme.titleMedium, + ), + const SizedBox(width: 30), + IconButton( + iconSize: 40.0, + padding: const EdgeInsets.all(8), + style: const ButtonStyle( + tapTargetSize: + MaterialTapTargetSize.shrinkWrap, // the '2023' part + ), + tooltip: "${MineController.anonymity ? '退出' : '进入'}无痕模式", + onPressed: () { + MineController.onChangeAnonymity(context); + setState(() {}); + }, + icon: Icon( + MineController.anonymity + ? MdiIcons.incognito + : MdiIcons.incognitoOff, + size: 24, + ), + ), + IconButton( + iconSize: 40.0, + padding: const EdgeInsets.all(8), + constraints: const BoxConstraints(), + style: const ButtonStyle( + tapTargetSize: + MaterialTapTargetSize.shrinkWrap, // the '2023' part + ), + tooltip: '切换至${switch (mineController.nextThemeType) { + ThemeType.light => '浅色', + ThemeType.dark => '深色', + ThemeType.system => '跟随系统', + }}主题', + onPressed: mineController.onChangeTheme, + icon: Icon( + switch (mineController.themeType.value) { + ThemeType.light => MdiIcons.weatherSunny, + ThemeType.dark => MdiIcons.weatherNight, + ThemeType.system => MdiIcons.themeLightDark, + }, + size: 24, + ), + ), + IconButton( + iconSize: 40.0, + padding: const EdgeInsets.all(8), + constraints: const BoxConstraints(), + style: const ButtonStyle( + tapTargetSize: + MaterialTapTargetSize.shrinkWrap, // the '2023' part + ), + tooltip: '设置', + onPressed: () => { + Get.back(), + Get.toNamed('/setting', preventDuplicates: false), + }, + icon: Icon( + MdiIcons.cogs, + size: 24, + ), + ), + const SizedBox(width: 10), + ], + ), + ); + @override Widget build(BuildContext context) { - // 宽度以最长的行为准,便于两端对齐 return IntrinsicWidth( - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - // mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox(height: 8), - Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const SizedBox(width: 12), - Image.asset( - 'assets/images/logo/logo_android_2.png', - width: 35, - ), - const SizedBox(width: 5), - Text( - 'PiliPalaX', - style: Theme.of(context).textTheme.titleMedium, - ), - const SizedBox(width: 30), - IconButton( - iconSize: 40.0, - padding: const EdgeInsets.all(8), - // constraints: const BoxConstraints(), - style: const ButtonStyle( - tapTargetSize: - MaterialTapTargetSize.shrinkWrap, // the '2023' part - ), - tooltip: "${MineController.anonymity ? '退出' : '进入'}无痕模式", - onPressed: () { - MineController.onChangeAnonymity(context); - setState(() {}); - }, - icon: Icon( - MineController.anonymity - ? MdiIcons.incognito - : MdiIcons.incognitoOff, - size: 24, - ), - ), - IconButton( - iconSize: 40.0, - padding: const EdgeInsets.all(8), - constraints: const BoxConstraints(), - style: const ButtonStyle( - tapTargetSize: - MaterialTapTargetSize.shrinkWrap, // the '2023' part - ), - tooltip: '切换至${switch (mineController.nextThemeType) { - ThemeType.light => '浅色', - ThemeType.dark => '深色', - ThemeType.system => '跟随系统', - }}主题', - onPressed: mineController.onChangeTheme, - icon: Icon( - switch (mineController.themeType.value) { - ThemeType.light => MdiIcons.weatherSunny, - ThemeType.dark => MdiIcons.weatherNight, - ThemeType.system => MdiIcons.themeLightDark, - }, - size: 24, - ), - ), - IconButton( - iconSize: 40.0, - padding: const EdgeInsets.all(8), - constraints: const BoxConstraints(), - style: const ButtonStyle( - tapTargetSize: - MaterialTapTargetSize.shrinkWrap, // the '2023' part - ), - tooltip: '设置', - onPressed: () => { - Get.back(), - Get.toNamed('/setting', preventDuplicates: false), - }, - icon: Icon( - MdiIcons.cogs, - size: 24, - ), - ), - const SizedBox(width: 10), - ]), - const SizedBox(height: 10), - FutureBuilder( - future: _futureBuilderFuture, - builder: (context, snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - if (snapshot.data == null || !snapshot.data['status']) { + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox(height: 8), + _header, + const SizedBox(height: 10), + FutureBuilder( + future: _futureBuilderFuture, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.data == null || !snapshot.data['status']) { + return userInfoBuild(mineController, context); + } + return Obx(() => userInfoBuild(mineController, context)); + } else { return userInfoBuild(mineController, context); } - return Obx(() => userInfoBuild(mineController, context)); - } else { - return userInfoBuild(mineController, context); - } - }, - ), - ], - )); + }, + ), + ], + ), + ); } Widget userInfoBuild(_mineController, context) { LevelInfo? levelInfo = _mineController.userInfo.value.levelInfo; TextStyle style = TextStyle( - fontSize: Theme.of(context).textTheme.titleMedium!.fontSize, - color: Theme.of(context).colorScheme.primary, - fontWeight: FontWeight.bold); - return Column(mainAxisSize: MainAxisSize.min, children: [ - Row( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox(width: 20), - GestureDetector( - onTap: () => _mineController.onLogin(), - child: ClipOval( - child: Container( - width: 70, - height: 70, - color: Theme.of(context).colorScheme.onInverseSurface, - child: Center( - child: _mineController.userInfo.value.face != null - ? NetworkImgLayer( - src: _mineController.userInfo.value.face, - semanticsLabel: '头像', - width: 70, - height: 70) - : Image.asset( - 'assets/images/noface.jpeg', - semanticLabel: "默认头像", - ), + fontSize: Theme.of(context).textTheme.titleMedium!.fontSize, + color: Theme.of(context).colorScheme.primary, + fontWeight: FontWeight.bold, + ); + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox(width: 20), + GestureDetector( + onTap: _mineController.onLogin, + child: ClipOval( + child: Container( + width: 70, + height: 70, + color: Theme.of(context).colorScheme.onInverseSurface, + child: Center( + child: _mineController.userInfo.value.face != null + ? NetworkImgLayer( + src: _mineController.userInfo.value.face, + semanticsLabel: '头像', + width: 70, + height: 70, + ) + : Image.asset( + 'assets/images/noface.jpeg', + semanticLabel: "默认头像", + ), + ), ), ), ), - ), - const SizedBox(width: 16), - IntrinsicWidth( + const SizedBox(width: 16), + Expanded( child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - _mineController.userInfo.value.uname ?? '点击头像登录', - style: Theme.of(context).textTheme.titleMedium, + FittedBox( + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + _mineController.userInfo.value.uname ?? '点击头像登录', + style: Theme.of(context).textTheme.titleMedium, + ), + const SizedBox(width: 4), + Image.asset( + 'assets/images/lv/lv${_mineController.userInfo.value.levelInfo != null ? _mineController.userInfo.value.levelInfo!.currentLevel : '0'}.png', + height: 10, + semanticLabel: + '等级:${_mineController.userInfo.value.levelInfo != null ? _mineController.userInfo.value.levelInfo!.currentLevel : '0'}', + ), + ], + ), ), - const SizedBox(width: 4), - Image.asset( - 'assets/images/lv/lv${_mineController.userInfo.value.levelInfo != null ? _mineController.userInfo.value.levelInfo!.currentLevel : '0'}.png', - height: 10, - semanticLabel: - '等级:${_mineController.userInfo.value.levelInfo != null ? _mineController.userInfo.value.levelInfo!.currentLevel : '0'}', + const SizedBox(height: 8), + FittedBox( + child: Text.rich( + TextSpan( + children: [ + TextSpan( + text: '硬币 ', + style: TextStyle( + fontSize: Theme.of(context) + .textTheme + .labelSmall! + .fontSize, + color: Theme.of(context).colorScheme.outline, + ), + ), + TextSpan( + text: (_mineController.userInfo.value.money ?? '-') + .toString(), + style: TextStyle( + fontSize: Theme.of(context) + .textTheme + .labelSmall! + .fontSize, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), + TextSpan( + text: " 经验 ", + style: TextStyle( + fontSize: Theme.of(context) + .textTheme + .labelSmall! + .fontSize, + color: Theme.of(context).colorScheme.outline, + ), + ), + TextSpan( + text: "${levelInfo?.currentExp ?? '-'}", + semanticsLabel: "当前${levelInfo?.currentExp ?? '-'}", + style: TextStyle( + fontSize: Theme.of(context) + .textTheme + .labelSmall! + .fontSize, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), + TextSpan( + text: "/${levelInfo?.nextExp ?? '-'}", + semanticsLabel: "升级需${levelInfo?.nextExp ?? '-'}", + style: TextStyle( + fontSize: Theme.of(context) + .textTheme + .labelSmall! + .fontSize, + color: Theme.of(context).colorScheme.outline, + ), + ), + ], + ), + ), + ), + const SizedBox(height: 4), + LinearProgressIndicator( + minHeight: 2, + value: levelInfo != null + ? (levelInfo.currentExp! / levelInfo.nextExp!) + : 0, + backgroundColor: + Theme.of(context).colorScheme.inversePrimary, + valueColor: AlwaysStoppedAnimation( + Theme.of(context).colorScheme.primary), ), ], ), - const SizedBox(height: 8), - Text.rich(TextSpan(children: [ - TextSpan( - text: '硬币 ', - style: TextStyle( - fontSize: - Theme.of(context).textTheme.labelSmall!.fontSize, - color: Theme.of(context).colorScheme.outline)), - TextSpan( - text: (_mineController.userInfo.value.money ?? '-') - .toString(), - style: TextStyle( - fontSize: - Theme.of(context).textTheme.labelSmall!.fontSize, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.primary)), - TextSpan( - text: " 经验 ", - style: TextStyle( - fontSize: - Theme.of(context).textTheme.labelSmall!.fontSize, - color: Theme.of(context).colorScheme.outline)), - TextSpan( - text: "${levelInfo?.currentExp ?? '-'}", - semanticsLabel: "当前${levelInfo?.currentExp ?? '-'}", - style: TextStyle( - fontSize: - Theme.of(context).textTheme.labelSmall!.fontSize, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.primary)), - TextSpan( - text: "/${levelInfo?.nextExp ?? '-'}", - semanticsLabel: "升级需${levelInfo?.nextExp ?? '-'}", - style: TextStyle( - fontSize: - Theme.of(context).textTheme.labelSmall!.fontSize, - color: Theme.of(context).colorScheme.outline)), - ])), - // const SizedBox(height: 4), - // Text.rich(TextSpan(children: [ - // ])), - // Text.rich( - // textAlign: TextAlign.right, - // TextSpan(children: [ - // - // ])), - const SizedBox(height: 4), - LinearProgressIndicator( - minHeight: 2, - value: levelInfo != null - ? (levelInfo.currentExp! / levelInfo.nextExp!) - : 0, - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - valueColor: AlwaysStoppedAnimation( - Theme.of(context).colorScheme.primary), - ), - ], - )), - const SizedBox(width: 20), - ], - ), - const SizedBox(height: 10), - Container( + ), + const SizedBox(width: 20), + ], + ), + const SizedBox(height: 10), + SizedBox( width: 240, height: 100, child: GridView.count( @@ -268,7 +296,7 @@ class _MinePageState extends State { crossAxisCount: 3, children: [ InkWell( - onTap: () => _mineController.pushDynamic(), + onTap: _mineController.pushDynamic, borderRadius: StyleString.mdRadius, child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -280,12 +308,13 @@ class _MinePageState extends State { return ScaleTransition(scale: animation, child: child); }, child: Text( - (_mineController.userStat.value.dynamicCount ?? '-') - .toString(), - key: ValueKey(_mineController - .userStat.value.dynamicCount - .toString()), - style: style), + (_mineController.userStat.value.dynamicCount ?? '-') + .toString(), + key: ValueKey(_mineController + .userStat.value.dynamicCount + .toString()), + style: style, + ), ), const SizedBox(height: 8), Text( @@ -296,7 +325,7 @@ class _MinePageState extends State { ), ), InkWell( - onTap: () => _mineController.pushFollow(), + onTap: _mineController.pushFollow, borderRadius: StyleString.mdRadius, child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -308,12 +337,13 @@ class _MinePageState extends State { return ScaleTransition(scale: animation, child: child); }, child: Text( - (_mineController.userStat.value.following ?? '-') - .toString(), - key: ValueKey(_mineController - .userStat.value.following - .toString()), - style: style), + (_mineController.userStat.value.following ?? '-') + .toString(), + key: ValueKey(_mineController + .userStat.value.following + .toString()), + style: style, + ), ), const SizedBox(height: 8), Text( @@ -324,7 +354,7 @@ class _MinePageState extends State { ), ), InkWell( - onTap: () => _mineController.pushFans(), + onTap: _mineController.pushFans, borderRadius: StyleString.mdRadius, child: Column( mainAxisSize: MainAxisSize.min, @@ -337,12 +367,12 @@ class _MinePageState extends State { return ScaleTransition(scale: animation, child: child); }, child: Text( - (_mineController.userStat.value.follower ?? '-') - .toString(), - key: ValueKey(_mineController - .userStat.value.follower - .toString()), - style: style), + (_mineController.userStat.value.follower ?? '-') + .toString(), + key: ValueKey( + _mineController.userStat.value.follower.toString()), + style: style, + ), ), const SizedBox(height: 8), Text( @@ -353,39 +383,9 @@ class _MinePageState extends State { ), ), ], - )), - ]); - } -} - -class ActionItem extends StatelessWidget { - final Icon? icon; - final Function? onTap; - final String? text; - - const ActionItem({ - super.key, - this.icon, - this.onTap, - this.text, - }); - - @override - Widget build(BuildContext context) { - return InkWell( - onTap: () {}, - borderRadius: StyleString.mdRadius, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon(icon!.icon!), - const SizedBox(height: 8), - Text( - text!, - style: Theme.of(context).textTheme.labelMedium, ), - ], - ), + ), + ], ); } }