From 15867bb177c84d0ec607ab04e9a344923bd3e935 Mon Sep 17 00:00:00 2001 From: gitea Date: Sun, 15 Feb 2026 20:58:24 +0100 Subject: [PATCH] layout improvements --- lib/screens/community_decks_screen.dart | 100 +++++++++++++----------- lib/screens/deck_config_screen.dart | 25 ++++-- lib/screens/deck_list_screen.dart | 18 +++-- lib/screens/home_screen.dart | 34 +++++--- lib/screens/login_screen.dart | 3 +- 5 files changed, 106 insertions(+), 74 deletions(-) diff --git a/lib/screens/community_decks_screen.dart b/lib/screens/community_decks_screen.dart index b3843fc..4ec75f6 100644 --- a/lib/screens/community_decks_screen.dart +++ b/lib/screens/community_decks_screen.dart @@ -69,15 +69,6 @@ class CommunityDecksScreenState extends State { } Future _load() async { - final user = ApiAuthService.instance.currentUser.value; - if (user == null) { - setState(() { - _loading = false; - _decks = []; - _error = null; - }); - return; - } setState(() { _loading = true; _error = null; @@ -179,34 +170,6 @@ class CommunityDecksScreenState extends State { Widget build(BuildContext context) { final user = ApiAuthService.instance.currentUser.value; - if (user == null) { - final body = Center( - child: Padding( - padding: const EdgeInsets.all(24), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'Log in to browse and add community decks.', - style: Theme.of(context).textTheme.bodyLarge, - textAlign: TextAlign.center, - ), - const SizedBox(height: 24), - FilledButton( - onPressed: () => Navigator.pushNamed(context, Routes.login) - .then((_) => _load()), - child: const Text('Log in'), - ), - ], - ), - ), - ); - if (widget.showAppBar) { - return Scaffold(appBar: AppBar(title: const Text('Community decks')), body: body); - } - return body; - } - final body = _loading ? const Center(child: CircularProgressIndicator()) : _error != null @@ -270,11 +233,48 @@ class CommunityDecksScreenState extends State { maxLines: 2, overflow: TextOverflow.ellipsis, ), - const SizedBox(height: 4), - Text( - '${d.questionCount} questions' - '${d.ownerDisplayName != null ? ' ยท ${d.ownerDisplayName}' : ''}', - style: Theme.of(context).textTheme.bodySmall, + const SizedBox(height: 6), + Row( + children: [ + Icon( + Icons.person_outline, + size: 14, + color: Theme.of(context).colorScheme.onSurfaceVariant, + ), + const SizedBox(width: 4), + Text( + d.ownerDisplayName != null && d.ownerDisplayName!.isNotEmpty + ? d.ownerDisplayName! + : 'Unknown', + style: Theme.of(context).textTheme.bodySmall?.copyWith( + color: Theme.of(context).colorScheme.onSurfaceVariant, + ), + ), + ], + ), + const SizedBox(height: 2), + Row( + children: [ + Text( + '${d.questionCount} questions', + style: Theme.of(context).textTheme.bodySmall, + ), + if (d.averageRating != null) ...[ + const SizedBox(width: 12), + Icon( + Icons.star, + size: 14, + color: Theme.of(context).colorScheme.primary, + ), + const SizedBox(width: 2), + Text( + d.ratingCount != null && d.ratingCount! > 0 + ? '${d.averageRating!.toStringAsFixed(1)} (${d.ratingCount})' + : d.averageRating!.toStringAsFixed(1), + style: Theme.of(context).textTheme.bodySmall, + ), + ], + ], ), ], ), @@ -287,10 +287,18 @@ class CommunityDecksScreenState extends State { vertical: 4, ), ) - : FilledButton.tonal( - onPressed: () => _addToMyDecks(d), - child: const Text('Add'), - ), + : user == null + ? FilledButton.tonal( + onPressed: () => Navigator.pushNamed( + context, + Routes.login, + ).then((_) => _load()), + child: const Text('Log in to add'), + ) + : FilledButton.tonal( + onPressed: () => _addToMyDecks(d), + child: const Text('Add'), + ), ), ); }, diff --git a/lib/screens/deck_config_screen.dart b/lib/screens/deck_config_screen.dart index e1f1934..5d3baf1 100644 --- a/lib/screens/deck_config_screen.dart +++ b/lib/screens/deck_config_screen.dart @@ -367,13 +367,23 @@ class _DeckConfigScreenState extends State { ); } - return Scaffold( - appBar: AppBar( - title: const Text('Attempt Settings'), - leading: IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () => Navigator.pop(context, _deck), - ), + return PopScope( + canPop: false, + onPopInvokedWithResult: (didPop, result) { + if (didPop) return; + _applyAndPersist(); + if (mounted) Navigator.pop(context, _deck); + }, + child: Scaffold( + appBar: AppBar( + title: const Text('Attempt Settings'), + leading: IconButton( + icon: const Icon(Icons.arrow_back), + onPressed: () { + _applyAndPersist(); + if (mounted) Navigator.pop(context, _deck); + }, + ), actions: [ IconButton( icon: const Icon(Icons.code), @@ -667,6 +677,7 @@ class _DeckConfigScreenState extends State { ], ), ), + ), ); } } diff --git a/lib/screens/deck_list_screen.dart b/lib/screens/deck_list_screen.dart index 5d6e055..7bf3c6c 100644 --- a/lib/screens/deck_list_screen.dart +++ b/lib/screens/deck_list_screen.dart @@ -683,9 +683,15 @@ class DeckListScreenState extends State { valueListenable: ApiAuthService.instance.currentUser, builder: (context, user, _) { if (user == null) { - return FilledButton.tonal( - onPressed: () => Navigator.of(context).pushNamed(Routes.login), - child: const Text('Log in'), + return Padding( + padding: const EdgeInsets.only(right: 12), + child: FilledButton.tonal( + style: FilledButton.styleFrom( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8), + ), + onPressed: () => Navigator.of(context).pushNamed(Routes.login), + child: const Text('Log in'), + ), ); } return Row( @@ -716,10 +722,10 @@ class DeckListScreenState extends State { ], onSelected: (value) async { if (value != 'logout') return; - final navigator = Navigator.of(context); await ApiAuthService.instance.logout(); - navigator.pushNamedAndRemoveUntil( - Routes.login, + if (!mounted) return; + Navigator.of(context).pushNamedAndRemoveUntil( + Routes.deckList, (route) => false, ); }, diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index e50c899..808f764 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -61,9 +61,15 @@ class _HomeScreenState extends State { valueListenable: ApiAuthService.instance.currentUser, builder: (context, user, _) { if (user == null) { - return FilledButton.tonal( - onPressed: () => Navigator.of(context).pushNamed(Routes.login), - child: const Text('Log in'), + return Padding( + padding: const EdgeInsets.only(right: 12), + child: FilledButton.tonal( + style: FilledButton.styleFrom( + padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8), + ), + onPressed: () => Navigator.of(context).pushNamed(Routes.login), + child: const Text('Log in'), + ), ); } return Row( @@ -94,10 +100,10 @@ class _HomeScreenState extends State { ], onSelected: (value) async { if (value != 'logout') return; - final navigator = Navigator.of(context); await ApiAuthService.instance.logout(); - navigator.pushNamedAndRemoveUntil( - Routes.login, + if (!mounted) return; + Navigator.of(context).pushNamedAndRemoveUntil( + Routes.deckList, (route) => false, ); }, @@ -123,10 +129,12 @@ class _HomeScreenState extends State { ), floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, bottomNavigationBar: BottomAppBar( - notchMargin: 8, + notchMargin: 2, + padding: EdgeInsets.zero, + height: 40, child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ _NavItem( icon: Icons.folder, label: 'My Decks', @@ -166,16 +174,16 @@ class _NavItem extends StatelessWidget { onTap: onTap, customBorder: const CircleBorder(), child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), + padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 0), child: Row( mainAxisSize: MainAxisSize.min, children: [ - Icon(icon, size: 22, color: selected ? Theme.of(context).colorScheme.primary : null), - const SizedBox(width: 6), + Icon(icon, size: 18, color: selected ? Theme.of(context).colorScheme.primary : null), + const SizedBox(width: 4), Text( label, style: TextStyle( - fontSize: 12, + fontSize: 10, color: selected ? Theme.of(context).colorScheme.primary : null, ), ), diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index 0be0db7..f051454 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -1,6 +1,5 @@ import 'package:flutter/material.dart'; -import '../routes.dart'; import '../services/api_auth_service.dart'; class LoginScreen extends StatefulWidget { @@ -54,7 +53,7 @@ class _LoginScreenState extends State { }); if (err == null) { - Navigator.pushReplacementNamed(context, Routes.deckList); + Navigator.pop(context); } }