15.3 功能列表、注销
实现步骤:
lib/pages/my/my_index/widgets/button_item.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_woo_commerce_getx_learn/common/index.dart';
class ButtonItemWidget extends StatelessWidget { final String title; final String svgPath; final Color? color; final Function()? onTap;
const ButtonItemWidget({ Key? key, required this.title, required this.svgPath, this.color, this.onTap, }) : super(key: key);
@override Widget build(BuildContext context) { var color = this.color ?? AppColors.primary; return ListTileWidget( leading: <Widget>[ Container().tightSize(30.w).decorated( color: color.withOpacity(0.2), borderRadius: BorderRadius.circular(30.w / 2), ),
IconWidget.svg( svgPath, color: color, size: 14.w, ), ].toStack( alignment: Alignment.center, ),
leadingSpace: 20.w,
title: TextWidget.body1( title, size: 15.sp, weight: FontWeight.w400, ),
trailing: <Widget>[ IconWidget.icon( Icons.arrow_forward_ios, size: 14.w, color: AppColors.outline, ), ], ).inkWell( onTap: onTap, ); } }
|
第 2 步:视图
lib/pages/my/my_index/view.dart
1 2 3 4 5 6 7 8 9
| Widget _buildMyOrder() { return ButtonItemWidget( title: LocaleKeys.myBtnMyOrder.tr, svgPath: AssetsSvgs.pDeliverySvg, color: "4061FF".toColor, onTap: () => Get.toNamed(RouteNames.myOrderList), ).card().paddingVertical(AppSpace.page); }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Widget _buildButtonsList() { return <Widget>[ ButtonItemWidget( title: LocaleKeys.myBtnEditProfile.tr, svgPath: AssetsSvgs.pCurrencySvg, color: "4971FF".toColor, onTap: () => Get.toNamed(RouteNames.myProfileEdit), ),
ButtonItemWidget( title: LocaleKeys.myBtnBillingAddress.tr, svgPath: AssetsSvgs.pHomeSvg, color: "F43284".toColor, ),
ButtonItemWidget( title: LocaleKeys.myBtnShippingAddress.tr, svgPath: AssetsSvgs.pHomeSvg, color: "5F84FF".toColor, ),
ButtonItemWidget( title: LocaleKeys.myBtnLanguage.tr, svgPath: AssetsSvgs.pTranslateSvg, color: "41AA3D".toColor, onTap: () => Get.toNamed(RouteNames.myLanguage), ),
ButtonItemWidget( title: LocaleKeys.myBtnTheme.tr, svgPath: AssetsSvgs.pThemeSvg, color: "F89C52".toColor, onTap: () => ConfigService.to.switchThemeModel(), ),
ButtonItemWidget( title: LocaleKeys.myBtnStyles.tr, svgPath: AssetsSvgs.pCurrencySvg, color: "4971FF".toColor, onTap: () => Get.toNamed(RouteNames.stylesStylesIndex), ),
].toColumn().card().paddingBottom(30.h); }
|
第 3 步:用户注销
用户 service
lib/common/services/user.dart
1 2 3 4 5 6 7
| Future<void> logout() async { await Storage().remove(Constants.storageToken); _profile(UserProfileModel()); _isLogin.value = false; token = ''; }
|
删除本地 token
, 清空 profile
资料
控制器
lib/pages/my/my_index/controller.dart
1 2 3 4 5
| void onLogout() { UserService.to.logout(); Get.find<MainController>().onJumpToPage(0); }
|
视图
lib/pages/my/my_index/view.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| Widget _buildView() { return CustomScrollView( slivers: <Widget>[ ...
ButtonWidget.primary( LocaleKeys.myBtnLogout.tr, height: 60, onTap: () => controller.onLogout(), ) .padding( left: AppSpace.page, right: AppSpace.page, bottom: AppSpace.listRow * 2, ) .sliverBox,
|
提交代码到 git