From 7bb8d2b33fac87465e49e4885225b0b036aa3963 Mon Sep 17 00:00:00 2001 From: shilangyu Date: Tue, 3 May 2022 09:44:07 +0200 Subject: [PATCH] Fix code review comments --- lib/comment_tree.dart | 1 - .../create_post_community_picker.dart | 114 ++++++++++-------- lib/pages/create_post/create_post_store.dart | 4 +- .../create_post/create_post_url_field.dart | 2 +- 4 files changed, 65 insertions(+), 56 deletions(-) diff --git a/lib/comment_tree.dart b/lib/comment_tree.dart index 2de4053..f935dac 100644 --- a/lib/comment_tree.dart +++ b/lib/comment_tree.dart @@ -5,7 +5,6 @@ import 'util/hot_rank.dart'; enum CommentSortType { hot, top, - // ignore: constant_identifier_names new_, old, chat, diff --git a/lib/pages/create_post/create_post_community_picker.dart b/lib/pages/create_post/create_post_community_picker.dart index 9db2925..33ddd31 100644 --- a/lib/pages/create_post/create_post_community_picker.dart +++ b/lib/pages/create_post/create_post_community_picker.dart @@ -32,63 +32,73 @@ class CreatePostCommunityPicker extends HookWidget { controller.text = ''; } }, - child: TypeAheadFormField( - textFieldConfiguration: TextFieldConfiguration( - controller: controller, - enabled: !store.isEdit, - decoration: InputDecoration( - hintText: L10n.of(context).community, - contentPadding: const EdgeInsets.symmetric( - vertical: 16, - horizontal: 20, + child: ObserverBuilder(builder: (context, store) { + return TypeAheadFormField( + textFieldConfiguration: TextFieldConfiguration( + controller: controller, + enabled: !store.isEdit, + decoration: InputDecoration( + hintText: L10n.of(context).community, + contentPadding: const EdgeInsets.symmetric( + vertical: 16, + horizontal: 20, + ), + suffixIcon: store.selectedCommunity == null + ? const Icon(Icons.arrow_drop_down) + : IconButton( + onPressed: () { + store.selectedCommunity = null; + controller.clear(); + }, + icon: const Icon(Icons.close), + ), ), - suffixIcon: const Icon(Icons.arrow_drop_down), + onChanged: (_) => store.selectedCommunity = null, ), - onChanged: (_) => store.selectedCommunity = null, - ), - validator: Validators.required(L10n.of(context).required_field), - suggestionsCallback: (pattern) async { - final communities = await store.searchCommunities( - pattern, - context.defaultJwt(store.instanceHost), - ); + validator: Validators.required(L10n.of(context).required_field), + suggestionsCallback: (pattern) async { + final communities = await store.searchCommunities( + pattern, + context.defaultJwt(store.instanceHost), + ); - return communities ?? []; - }, - itemBuilder: (context, community) { - return ListTile( - leading: Avatar( - url: community.community.icon, - radius: 20, - ), - title: Text(_communityString(community)), - ); - }, - onSuggestionSelected: (community) { - store.selectedCommunity = community; - controller.text = _communityString(community); - }, - noItemsFoundBuilder: (context) => SizedBox( - width: double.infinity, - child: Padding( - padding: const EdgeInsets.all(8), - child: Text( - L10n.of(context).no_communities_found, - textAlign: TextAlign.center, + return communities ?? []; + }, + itemBuilder: (context, community) { + return ListTile( + leading: Avatar( + url: community.community.icon, + radius: 20, + ), + title: Text(_communityString(community)), + ); + }, + onSuggestionSelected: (community) { + store.selectedCommunity = community; + controller.text = _communityString(community); + }, + noItemsFoundBuilder: (context) => SizedBox( + width: double.infinity, + child: Padding( + padding: const EdgeInsets.all(8), + child: Text( + L10n.of(context).no_communities_found, + textAlign: TextAlign.center, + ), ), ), - ), - loadingBuilder: (context) => Row( - mainAxisAlignment: MainAxisAlignment.center, - children: const [ - Padding( - padding: EdgeInsets.all(8), - child: CircularProgressIndicator.adaptive(), - ), - ], - ), - debounceDuration: const Duration(milliseconds: 400), - ), + loadingBuilder: (context) => Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Padding( + padding: EdgeInsets.all(8), + child: CircularProgressIndicator.adaptive(), + ), + ], + ), + debounceDuration: const Duration(milliseconds: 400), + ); + }), ), ); } diff --git a/lib/pages/create_post/create_post_store.dart b/lib/pages/create_post/create_post_store.dart index 687360b..b0f2e06 100644 --- a/lib/pages/create_post/create_post_store.dart +++ b/lib/pages/create_post/create_post_store.dart @@ -59,7 +59,7 @@ abstract class _CreatePostStore with Store { ListCommunities( type: PostListingType.all, sort: SortType.topAll, - limit: 20, + limit: 10, auth: token?.raw, ), ); @@ -70,7 +70,7 @@ abstract class _CreatePostStore with Store { q: searchTerm, sort: SortType.topAll, listingType: PostListingType.all, - limit: 20, + limit: 10, auth: token?.raw, ), ); diff --git a/lib/pages/create_post/create_post_url_field.dart b/lib/pages/create_post/create_post_url_field.dart index ef5bf0f..5f8ce2b 100644 --- a/lib/pages/create_post/create_post_url_field.dart +++ b/lib/pages/create_post/create_post_url_field.dart @@ -34,7 +34,7 @@ class CreatePostUrlField extends HookWidget { return ObserverConsumer( listener: (context, store) { - // needed since flutter's TextFields cannot work as dumb widgets + // needed to keep the controller and store data in sync if (controller.text != store.url) { controller.text = store.url; }