From 49e626e95a46c09f0655e675011b909e11804a2e Mon Sep 17 00:00:00 2001 From: Key Date: Thu, 29 Jun 2023 20:22:54 +0800 Subject: [PATCH] feat: log_util.dart --- assets/images/bg_edit_information.png | Bin 0 -> 515630 bytes lib/common/core/assets_const.dart | 1 + lib/pages/home/home_page.dart | 4 ++-- lib/pages/user/information/user_information_bloc.dart | 13 ------------- lib/pages/user/information/user_information_event.dart | 4 ---- lib/pages/user/information/user_information_page.dart | 37 +++++++++++++++++++++---------------- lib/pages/user/information/user_information_state.dart | 6 ------ lib/pages/user/modify/modify_user_information_page.dart | 31 +++++++++++++++++++++++++++++++ lib/pages/user/user_page.dart | 7 ++++++- lib/utils/log_util.dart | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 116 insertions(+), 42 deletions(-) create mode 100644 assets/images/bg_edit_information.png delete mode 100644 lib/pages/user/information/user_information_bloc.dart delete mode 100644 lib/pages/user/information/user_information_event.dart delete mode 100644 lib/pages/user/information/user_information_state.dart create mode 100644 lib/pages/user/modify/modify_user_information_page.dart create mode 100644 lib/utils/log_util.dart diff --git a/assets/images/bg_edit_information.png b/assets/images/bg_edit_information.png new file mode 100644 index 0000000..3801005 Binary files /dev/null and b/assets/images/bg_edit_information.png differ diff --git a/lib/common/core/assets_const.dart b/lib/common/core/assets_const.dart index 8766f54..64a5f3b 100644 --- a/lib/common/core/assets_const.dart +++ b/lib/common/core/assets_const.dart @@ -4,5 +4,6 @@ class AssetsConst { static const String icVip = '${_assetImagePrefix}ic_vip.png'; static const String icNext = '${_assetImagePrefix}ic_next.png'; static const String bgUserInformationText = '${_assetImagePrefix}bg_user_information_text.png'; + static const String bgEditUserInformation = '${_assetImagePrefix}bg_edit_information.png'; //static String get icVip2 =>'ic_vip.png'.assetImg; } diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index 0bfff2b..fc058f2 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -37,8 +37,8 @@ class _HomePageView extends StatelessWidget { } else if (type == HeaderActionType.shop) { Navigator.of(AppRouter.context).pushNamed(AppRouteName.shop); } else if (type == HeaderActionType.user) { - // Navigator.of(AppRouter.context).pushNamed(AppRouteName.user); - Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic); + Navigator.of(AppRouter.context).pushNamed(AppRouteName.user); + // Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic); } else { // Navigator.of(AppRouter.context).pushNamed(AppRouteName.topicPic); } diff --git a/lib/pages/user/information/user_information_bloc.dart b/lib/pages/user/information/user_information_bloc.dart deleted file mode 100644 index 1094019..0000000 --- a/lib/pages/user/information/user_information_bloc.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:meta/meta.dart'; - -part 'user_information_event.dart'; -part 'user_information_state.dart'; - -class UserInformationBloc extends Bloc { - UserInformationBloc() : super(UserInformationInitial()) { - on((event, emit) { - // TODO: implement event handler - }); - } -} diff --git a/lib/pages/user/information/user_information_event.dart b/lib/pages/user/information/user_information_event.dart deleted file mode 100644 index 05f8a67..0000000 --- a/lib/pages/user/information/user_information_event.dart +++ /dev/null @@ -1,4 +0,0 @@ -part of 'user_information_bloc.dart'; - -@immutable -abstract class UserInformationEvent {} diff --git a/lib/pages/user/information/user_information_page.dart b/lib/pages/user/information/user_information_page.dart index 0b8b447..88e9496 100644 --- a/lib/pages/user/information/user_information_page.dart +++ b/lib/pages/user/information/user_information_page.dart @@ -5,9 +5,10 @@ import 'package:wow_english/common/core/assets_const.dart'; import 'package:wow_english/common/core/user_util.dart'; import 'package:wow_english/common/widgets/we_app_bar.dart'; import 'package:wow_english/models/user_entity.dart'; +import 'package:wow_english/pages/user/bloc/user_bloc.dart'; import 'package:wow_english/utils/image_util.dart'; -import 'user_information_bloc.dart'; +import '../modify/modify_user_information_page.dart'; class UserInformationPage extends StatelessWidget { const UserInformationPage({super.key}); @@ -15,7 +16,7 @@ class UserInformationPage extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => UserInformationBloc(), + create: (context) => UserBloc(), child: const _UserInformationView(), ); } @@ -26,9 +27,9 @@ class _UserInformationView extends StatelessWidget { @override Widget build(BuildContext context) { - return BlocListener( + return BlocListener( listener: (context, state) {}, - child: BlocBuilder(builder: (context, state) { + child: BlocBuilder(builder: (context, state) { return const _UserInformationContentView(); }), ); @@ -38,31 +39,34 @@ class _UserInformationView extends StatelessWidget { class _UserInformationContentView extends StatelessWidget { const _UserInformationContentView({super.key}); + void _openModifyPage(ModifyUserInformationType type) { + print('_openModifyPage($type)'); + } + @override Widget build(BuildContext context) { UserEntity user = UserUtil.getUser()!; return Scaffold( backgroundColor: Colors.white, - appBar: const WEAppBar(titleText: "个人信息",), + appBar: const WEAppBar( + titleText: "个人信息", + ), body: SingleChildScrollView( padding: EdgeInsets.only(left: 17.w, right: 17.w, top: 10.h, bottom: 22.h), child: Column( children: [ - buildContentRow( + _buildContentRow( '头像', CircleAvatar( radius: 22.5.r, - backgroundColor: Color(0xFF140C10), + backgroundColor: const Color(0xFF140C10), child: CircleAvatar( radius: 21.r, backgroundImage: ImageUtil.getImageProviderOnDefault(user.avatarUrl), ), - /*child: ClipOval( - child: OwImageWidget(name: user.avatarUrl ?? AssetsConst.wowLogo, fit: BoxFit.contain,), - )*/ )), 11.verticalSpace, - buildContentRow( + _buildContentRow( '名字', Text( user.name, @@ -71,9 +75,10 @@ class _UserInformationContentView extends StatelessWidget { color: const Color(0xFF333333), fontSize: 21.sp, ), - )), + ), + onTap: () => _openModifyPage(ModifyUserInformationType.name)), 11.verticalSpace, - buildContentRow( + _buildContentRow( '年龄', Text( user.age.toString(), @@ -84,7 +89,7 @@ class _UserInformationContentView extends StatelessWidget { ), )), 11.verticalSpace, - buildContentRow( + _buildContentRow( '性别', Text( user.getGenderString(), @@ -95,7 +100,7 @@ class _UserInformationContentView extends StatelessWidget { ), )), 11.verticalSpace, - buildContentRow( + _buildContentRow( '账号', Text( user.phoneNum, @@ -113,7 +118,7 @@ class _UserInformationContentView extends StatelessWidget { ); } - Widget buildContentRow(String filedName, Widget contentWidget, {bool isHideEndIcon = false, Function()? onTap}) { + Widget _buildContentRow(String filedName, Widget contentWidget, {bool isHideEndIcon = false, Function()? onTap}) { return GestureDetector( onTap: onTap, child: Container( diff --git a/lib/pages/user/information/user_information_state.dart b/lib/pages/user/information/user_information_state.dart deleted file mode 100644 index 98389bf..0000000 --- a/lib/pages/user/information/user_information_state.dart +++ /dev/null @@ -1,6 +0,0 @@ -part of 'user_information_bloc.dart'; - -@immutable -abstract class UserInformationState {} - -class UserInformationInitial extends UserInformationState {} diff --git a/lib/pages/user/modify/modify_user_information_page.dart b/lib/pages/user/modify/modify_user_information_page.dart new file mode 100644 index 0000000..dbdb6e6 --- /dev/null +++ b/lib/pages/user/modify/modify_user_information_page.dart @@ -0,0 +1,31 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:wow_english/common/widgets/we_app_bar.dart'; +import 'package:wow_english/pages/user/bloc/user_bloc.dart'; + +enum ModifyUserInformationType { + avatar('修改头像'), name('修改名字'), age('修改年龄'), gender('修改性别'); + + const ModifyUserInformationType(this.title); + + final String title; +} + +class ModifyUserInformationPage extends StatelessWidget { + final ModifyUserInformationType type; + + const ModifyUserInformationPage({super.key, required this.type}); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => UserBloc(), + child: Scaffold( + backgroundColor: Colors.white, + appBar: WEAppBar( + titleText: type.title, + ), + ), + ); + } +} diff --git a/lib/pages/user/user_page.dart b/lib/pages/user/user_page.dart index 4eac233..3a87e97 100644 --- a/lib/pages/user/user_page.dart +++ b/lib/pages/user/user_page.dart @@ -25,6 +25,8 @@ class UserPage extends StatelessWidget { class _UserView extends StatelessWidget { const _UserView({super.key}); + final String bannerUrl = ''; + @override Widget build(BuildContext context) { return _pageWidget(); @@ -62,7 +64,10 @@ class _UserView extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ // banner - Container(child: Image.asset(AssetsConst.wowLogo), constraints: BoxConstraints(maxHeight: 196.h)), + Offstage( + child: Container( + child: Image.asset(bannerUrl), constraints: BoxConstraints(maxHeight: 196.h)), + ), 30.verticalSpace, Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, diff --git a/lib/utils/log_util.dart b/lib/utils/log_util.dart new file mode 100644 index 0000000..a51b0de --- /dev/null +++ b/lib/utils/log_util.dart @@ -0,0 +1,55 @@ +enum LogLevel { debug, info, warning, error } + +class Log { + static LogLevel level = LogLevel.debug; + + /// debug + static void d(String message) { + if (level.index <= LogLevel.debug.index) { + print(message); + } + } + + /// info + static void i(String message) { + if (level.index <= LogLevel.info.index) { + print(message); + } + } + + /// warning + static void w(String message) { + if (level.index <= LogLevel.warning.index) { + print(message); + } + } + + /// error + static void e(String message) { + if (level.index <= LogLevel.error.index) { + print(message); + } + } +} + +extension LogExtension on String { + String logD() { + Log.d(this); + return this; + } + + String logI() { + Log.i(this); + return this; + } + + String logW() { + Log.w(this); + return this; + } + + String logE() { + Log.e(this); + return this; + } +} -- libgit2 0.22.2