Repository navigation
Student Clubs full redesign proposal: list rows, detail sheet, search and categories #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| import 'package:campus_flutter/base/networking/apis/tumdev/campus_backend.pb.dart'; | ||
| import 'package:campus_flutter/base/util/url_launcher.dart'; | ||
| import 'package:campus_flutter/campusComponent/model/student_club.dart'; | ||
| import 'package:campus_flutter/campusComponent/model/student_club_collection.dart'; | ||
| import 'package:campus_flutter/campusComponent/view/studentClub/student_club_card_view.dart'; | ||
| import 'package:campus_flutter/campusComponent/view/studentClub/student_club_list_tile.dart'; | ||
| import 'package:campus_flutter/campusComponent/view/shared/campus_collection_view.dart'; | ||
| import 'package:campus_flutter/campusComponent/viewmodel/student_club_viewmodel.dart'; | ||
| import 'package:easy_localization/easy_localization.dart'; | ||
|
|
@@ -16,6 +18,12 @@ class StudentClubsScreen extends ConsumerStatefulWidget { | |
|
|
||
| class _StudentClubsScreenState extends ConsumerState<StudentClubsScreen> { | ||
| Locale? _locale; | ||
| final _search = TextEditingController(); | ||
| String? _category; | ||
| bool _hasWebsite = false; | ||
|
|
||
| /// Lower-cased name and description, parsed once per club. | ||
| final _searchText = Expando<String>(); | ||
|
|
||
| @override | ||
| void didChangeDependencies() { | ||
|
|
@@ -31,77 +39,222 @@ class _StudentClubsScreenState extends ConsumerState<StudentClubsScreen> { | |
| _locale = locale; | ||
| } | ||
|
|
||
| @override | ||
| void dispose() { | ||
| _search.dispose(); | ||
| super.dispose(); | ||
| } | ||
|
|
||
| Future<void> _refresh() async => | ||
| await ref.read(studentClubViewModel).fetchStudentClubs(true, context); | ||
|
|
||
| bool get _isFiltering => _search.text.trim().isNotEmpty || _hasWebsite; | ||
|
|
||
| bool _matches(StudentClub club) { | ||
| if (_hasWebsite && !club.hasLink) return false; | ||
| final query = _search.text.trim().toLowerCase(); | ||
| if (query.isEmpty) return true; | ||
| final text = _searchText[club] ??= | ||
| '${club.parsedName}\n${club.parsedDescription}'.toLowerCase(); | ||
| return text.contains(query); | ||
| } | ||
|
|
||
| void _clearFilters() => setState(() { | ||
| _search.clear(); | ||
| _hasWebsite = false; | ||
| _category = null; | ||
| }); | ||
|
|
||
| void _pickCategory( | ||
| List<({String title, List<StudentClub> clubs})> categories, | ||
| String? selected, | ||
| ) => showModalBottomSheet<void>( | ||
| context: context, | ||
| showDragHandle: true, | ||
| isScrollControlled: true, | ||
| useSafeArea: true, | ||
| builder: (context) { | ||
| Widget option(String? title, String label, int count) => ListTile( | ||
| selected: title == selected, | ||
| leading: Icon(title == selected ? Icons.check : null), | ||
| title: Text(label), | ||
| trailing: Text('$count'), | ||
| onTap: () { | ||
| setState(() => _category = title); | ||
| Navigator.pop(context); | ||
| }, | ||
| ); | ||
| return ListView( | ||
| shrinkWrap: true, | ||
| padding: const EdgeInsets.only(bottom: 16), | ||
| children: [ | ||
| Padding( | ||
| padding: const EdgeInsets.fromLTRB(24, 0, 24, 8), | ||
| child: Text( | ||
| context.tr('studentClubCategories'), | ||
| style: Theme.of(context).textTheme.titleLarge, | ||
| ), | ||
| ), | ||
| option( | ||
| null, | ||
| context.tr('studentClubAllCategories'), | ||
| categories.fold(0, (sum, category) => sum + category.clubs.length), | ||
| ), | ||
| for (final category in categories) | ||
| option(category.title, category.title, category.clubs.length), | ||
| ], | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| Widget _header( | ||
| List<({String title, List<StudentClub> clubs})> categories, | ||
| String? selected, | ||
| ) { | ||
| // The app's chip theme only colours the label, so icons follow it. | ||
| final onChip = ChipTheme.of(context).labelStyle?.color; | ||
| return Padding( | ||
| padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.stretch, | ||
| children: [ | ||
| TextField( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would Flutter's SearchBar work here instead of styling a TextField as a search bar? It seems like a good fit for filtering the existing list and would let us use the standard search styling/theming. I think keeping the controller and filtering state local to this screen is appropriate; we wouldn't need a SearchAnchor or the app's global-search view model. This is a consistency suggestion rather than a functional concern. |
||
| controller: _search, | ||
| onChanged: (_) => setState(() {}), | ||
| onTapOutside: (_) => FocusScope.of(context).unfocus(), | ||
| textInputAction: TextInputAction.search, | ||
| decoration: InputDecoration( | ||
| hintText: context.tr('studentClubSearch'), | ||
| prefixIcon: const Icon(Icons.search), | ||
| suffixIcon: _search.text.isEmpty | ||
| ? null | ||
| : IconButton( | ||
| onPressed: () => setState(_search.clear), | ||
| tooltip: MaterialLocalizations.of(context) | ||
| .deleteButtonTooltip, | ||
| icon: const Icon(Icons.clear), | ||
| ), | ||
| border: OutlineInputBorder( | ||
| borderRadius: BorderRadius.circular(28), | ||
| ), | ||
| isDense: true, | ||
| ), | ||
| ), | ||
| const SizedBox(height: 8), | ||
| Row( | ||
| children: [ | ||
| Flexible( | ||
| child: FilterChip( | ||
| label: Row( | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: [ | ||
| Flexible( | ||
| child: Text( | ||
| selected ?? context.tr('studentClubAllCategories'), | ||
| overflow: TextOverflow.ellipsis, | ||
| ), | ||
| ), | ||
| Icon(Icons.arrow_drop_down, size: 18, color: onChip), | ||
| ], | ||
| ), | ||
| selected: selected != null, | ||
| onSelected: (_) => _pickCategory(categories, selected), | ||
| ), | ||
| ), | ||
| const SizedBox(width: 8), | ||
| // Leaves at least half the row to the category on narrow screens. | ||
| ConstrainedBox( | ||
| constraints: BoxConstraints( | ||
| maxWidth: MediaQuery.sizeOf(context).width / 2, | ||
| ), | ||
| child: FilterChip( | ||
| avatar: Icon(Icons.link, color: onChip), | ||
| label: Text( | ||
| context.tr('studentClubHasWebsite'), | ||
| overflow: TextOverflow.ellipsis, | ||
| ), | ||
| selected: _hasWebsite, | ||
| onSelected: (value) => setState(() => _hasWebsite = value), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) => StreamBuilder( | ||
| stream: ref.watch(studentClubViewModel).collections, | ||
| builder: (context, snapshot) { | ||
| final collections = snapshot.data ?? []; | ||
| Widget collection(int? index) { | ||
| final items = index == null ? null : collections[index].clubs; | ||
| return CampusCollectionView( | ||
| final categories = [ | ||
| for (final collection in collections) | ||
| ( | ||
| title: collection.parsedTitle, | ||
| clubs: collection.clubs.where(_matches).toList(), | ||
| ), | ||
| ]; | ||
| final selected = categories | ||
| .where((category) => category.title == _category) | ||
| .firstOrNull; | ||
| final sections = [ | ||
| for (final category in selected == null ? categories : [selected]) | ||
| CampusCollectionSection( | ||
| title: category.title, | ||
| trailing: '${category.clubs.length}', | ||
| itemCount: category.clubs.length, | ||
| itemBuilder: (context, index) => | ||
| StudentClubListTile(studentClub: category.clubs[index]), | ||
| ), | ||
| ]; | ||
|
|
||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: Text(context.tr('studentClubs')), | ||
| actions: [ | ||
| IconButton( | ||
| onPressed: _refresh, | ||
| tooltip: context.tr('refresh'), | ||
| icon: const Icon(Icons.refresh), | ||
| ), | ||
| IconButton( | ||
| onPressed: () => UrlLauncher.urlString( | ||
| context.locale.languageCode == 'de' | ||
| ? 'https://www.sv.tum.de/sv/hochschulgruppen/' | ||
| : 'https://www.sv.tum.de/en/sv/student-groups/', | ||
| ref, | ||
| ), | ||
| tooltip: context.tr('openWebsite'), | ||
| icon: const Icon(Icons.open_in_new), | ||
| ), | ||
| ], | ||
| ), | ||
| body: CampusCollectionView( | ||
| label: context.tr('studentClubs'), | ||
| icon: Icons.groups_outlined, | ||
| storageKey: index == null | ||
| ? 'clubs-empty' | ||
| : 'clubs-${collections[index].parsedTitle}', | ||
| storageKey: 'clubs-${selected?.title ?? 'all'}', | ||
| onRefresh: _refresh, | ||
| hasData: snapshot.hasData, | ||
| error: snapshot.error, | ||
| stackTrace: snapshot.stackTrace, | ||
|
|
||
| itemCount: items?.length ?? 0, | ||
| minimumCardWidth: 160, | ||
| cardAspectRatio: 1, | ||
| cardHeight: StudentClubCardView.heightFor(context), | ||
| itemBuilder: (context, index) => | ||
| StudentClubCardView(studentClub: items![index]), | ||
| ); | ||
| } | ||
|
|
||
| return DefaultTabController( | ||
| length: collections.length, | ||
| child: Scaffold( | ||
| appBar: AppBar( | ||
| title: Text(context.tr('studentClubs')), | ||
| actions: [ | ||
| IconButton( | ||
| onPressed: _refresh, | ||
| tooltip: context.tr('refresh'), | ||
| icon: const Icon(Icons.refresh), | ||
| ), | ||
| IconButton( | ||
| onPressed: () => UrlLauncher.urlString( | ||
| context.locale.languageCode == 'de' | ||
| ? 'https://www.sv.tum.de/sv/hochschulgruppen/' | ||
| : 'https://www.sv.tum.de/en/sv/student-groups/', | ||
| ref, | ||
| ), | ||
| tooltip: context.tr('openWebsite'), | ||
| icon: const Icon(Icons.open_in_new), | ||
| ), | ||
| ], | ||
| bottom: collections.isEmpty | ||
| ? null | ||
| : TabBar( | ||
| isScrollable: true, | ||
| tabAlignment: TabAlignment.start, | ||
| tabs: [ | ||
| for (final collection in collections) | ||
| Tab(text: collection.parsedTitle), | ||
| ], | ||
| ), | ||
| ), | ||
| body: collections.isEmpty | ||
| ? collection(null) | ||
| : TabBarView( | ||
| children: [ | ||
| for (var index = 0; index < collections.length; index++) | ||
| collection(index), | ||
| ], | ||
| ), | ||
| sections: sections, | ||
| header: collections.isEmpty | ||
| ? null | ||
| : _header(categories, selected?.title), | ||
| emptyMessage: _isFiltering | ||
| ? context.tr('studentClubNoMatches') | ||
| : null, | ||
| emptyAction: _isFiltering | ||
| ? TextButton.icon( | ||
| onPressed: _clearFilters, | ||
| icon: const Icon(Icons.filter_alt_off_outlined), | ||
| label: Text(context.tr('studentClubClearFilters')), | ||
| ) | ||
| : null, | ||
| minimumCardWidth: 340, | ||
| ), | ||
| ); | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small simplification: could we normalize the query once per filtering pass rather than once for every club? Also, the Expando caches the parsed text for searching, while the row and sheet still parse descriptions repeatedly through the extension getters. For this collection size, computing the description once per widget build may be sufficient; if we keep a broader cache, it would be nice to have one clear place where display/search text is prepared. No need for a larger state-management change here.