@@ -16,18 +16,19 @@ class _UserManagerState extends State<UserManager> {
1616 Color get themeColor => HexColor (settingsController.themeColorSwitch.value);
1717 final refreshController = EasyRefreshController (controlFinishRefresh: true , controlFinishLoad: true );
1818
19- Future onRefresh () async {
20- getCurrentUsers ();
21- refreshController.finishRefresh (IndicatorResult .success);
22- }
19+ final users = < String > [].obs;
2320
24- final users = [].obs;
2521 @override
2622 void initState () {
2723 getCurrentUsers ();
2824 super .initState ();
2925 }
3026
27+ Future onRefresh () async {
28+ await getCurrentUsers ();
29+ refreshController.finishRefresh (IndicatorResult .success);
30+ }
31+
3132 Future <void > getCurrentUsers () async {
3233 List <dynamic > data = await SupaBaseManager ().client.from (SupaBaseManager .supabasePolicy.checkTable).select ();
3334 if (data.isNotEmpty) {
@@ -36,24 +37,26 @@ class _UserManagerState extends State<UserManager> {
3637 }
3738
3839 void addUser () {
39- if (textEditingController.text.isEmpty || ! EmailValidator .validate (textEditingController.text)) {
40- ToastUtil .show ('请输入正确的邮箱' );
40+ final text = textEditingController.text.trim ();
41+ if (text.isEmpty || ! EmailValidator .validate (text)) {
42+ ToastUtil .show (i18n ('invalid_email' ));
4143 return ;
4244 }
43- if (users.contains (textEditingController. text. trim () )) {
44- ToastUtil .show ('邮箱已存在' );
45+ if (users.contains (text)) {
46+ ToastUtil .show (i18n ( 'email_exists' ) );
4547 return ;
4648 }
4749 SupaBaseManager ().client
4850 .from (SupaBaseManager .supabasePolicy.checkTable)
49- .insert ({SupaBaseManager .supabasePolicy.email: textEditingController. text. trim () })
51+ .insert ({SupaBaseManager .supabasePolicy.email: text})
5052 .then (
5153 (value) {
52- ToastUtil .show ('添加成功' );
53- users.add (textEditingController.text.trim ());
54+ ToastUtil .show (i18n ('add_success' ));
55+ users.add (text);
56+ textEditingController.clear ();
5457 },
5558 onError: (err) {
56- ToastUtil .show ('添加失败,请稍后重试' );
59+ ToastUtil .show (i18n ( 'add_failed' ) );
5760 },
5861 );
5962 }
@@ -65,73 +68,74 @@ class _UserManagerState extends State<UserManager> {
6568 .eq (SupaBaseManager .supabasePolicy.email, email)
6669 .then (
6770 (value) {
68- ToastUtil .show ('删除成功' );
71+ ToastUtil .show (i18n ( 'delete_success' ) );
6972 users.removeAt (index);
7073 },
7174 onError: (err) {
72- ToastUtil .show ('删除失败,请稍后重试' );
75+ ToastUtil .show (i18n ( 'delete_failed' ) );
7376 },
7477 );
7578 }
7679
7780 @override
7881 Widget build (BuildContext context) {
7982 return Scaffold (
80- appBar: AppBar (title: const Text ('用户管理' )),
81- body: Obx (
82- () => EasyRefresh (
83- controller: refreshController,
84- onRefresh: onRefresh,
85- onLoad: () {
86- refreshController.finishLoad (IndicatorResult .success);
87- },
88- child: ListView (
89- padding: const EdgeInsets .all (24.0 ),
90- children: [
91- TextField (
92- keyboardType: TextInputType .emailAddress,
93- controller: textEditingController,
94- decoration: InputDecoration (
95- prefixIcon: const Icon (Icons .email),
96- contentPadding: const EdgeInsets .all (12.0 ),
97- border: OutlineInputBorder (borderSide: BorderSide (color: themeColor)),
98- hintText: "请输入邮箱" ,
99- suffixIcon: TextButton .icon (onPressed: addUser, icon: const Icon (Icons .add), label: const Text ("添加" )),
83+ appBar: AppBar (title: Text (i18n ('manage_users' ))),
84+ body: EasyRefresh (
85+ controller: refreshController,
86+ onRefresh: onRefresh,
87+ onLoad: () {
88+ refreshController.finishLoad (IndicatorResult .success);
89+ },
90+ child: ListView (
91+ padding: const EdgeInsets .all (24.0 ),
92+ children: [
93+ TextField (
94+ keyboardType: TextInputType .emailAddress,
95+ controller: textEditingController,
96+ decoration: InputDecoration (
97+ prefixIcon: const Icon (Icons .email),
98+ contentPadding: const EdgeInsets .all (12.0 ),
99+ border: OutlineInputBorder (borderSide: BorderSide (color: themeColor)),
100+ hintText: i18n ('hint_text' ),
101+ suffixIcon: TextButton .icon (
102+ onPressed: addUser,
103+ icon: const Icon (Icons .add),
104+ label: Text (i18n ('add_btn' )),
100105 ),
101- onSubmitted: (e) {
102- addUser ();
103- },
104106 ),
105- spacer (12.0 ),
106- Obx (() => Text ("已添加${users .length }个用户(点击移除)" , style: Get .textTheme.titleMedium)),
107- spacer (12.0 ),
108- Obx (
109- () => Wrap (
110- runSpacing: 12 ,
111- spacing: 12 ,
112- children: users
113- .map (
114- (email) => InkWell (
115- borderRadius: const BorderRadius .all (Radius .circular (5.0 )),
116- onTap: () {
117- var index = users.indexWhere ((element) => element == email);
118- removeUser (email, index);
119- },
120- child: Container (
121- decoration: BoxDecoration (
122- border: Border .all (color: Theme .of (context).primaryColor),
123- borderRadius: const BorderRadius .all (Radius .circular (5.0 )),
124- ),
125- padding: const EdgeInsets .only (top: 10 , bottom: 10 , left: 8 , right: 8 ),
126- child: Text (email, style: Get .textTheme.bodyMedium),
127- ),
128- ),
129- )
130- .toList (),
131- ),
107+ onSubmitted: (e) => addUser (),
108+ ),
109+ spacer (12.0 ),
110+ // Using your custom helper with named parameters here
111+ Obx (
112+ () =>
113+ Text (i18n ('user_count' , args: {'count' : users.length.toString ()}), style: Get .textTheme.titleMedium),
114+ ),
115+ spacer (12.0 ),
116+ Obx (
117+ () => Wrap (
118+ runSpacing: 12 ,
119+ spacing: 12 ,
120+ children: users.asMap ().entries.map ((entry) {
121+ int index = entry.key;
122+ String email = entry.value;
123+ return InkWell (
124+ borderRadius: const BorderRadius .all (Radius .circular (5.0 )),
125+ onTap: () => removeUser (email, index),
126+ child: Container (
127+ decoration: BoxDecoration (
128+ border: Border .all (color: Theme .of (context).primaryColor),
129+ borderRadius: const BorderRadius .all (Radius .circular (5.0 )),
130+ ),
131+ padding: const EdgeInsets .only (top: 10 , bottom: 10 , left: 8 , right: 8 ),
132+ child: Text (email, style: Get .textTheme.bodyMedium),
133+ ),
134+ );
135+ }).toList (),
132136 ),
133- ] ,
134- ) ,
137+ ) ,
138+ ] ,
135139 ),
136140 ),
137141 );
0 commit comments