|
|
|
@ -8,7 +8,9 @@ import '../data/default_deck.dart';
|
|
|
|
import '../utils/top_snackbar.dart';
|
|
|
|
import '../utils/top_snackbar.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class DeckListScreen extends StatefulWidget {
|
|
|
|
class DeckListScreen extends StatefulWidget {
|
|
|
|
const DeckListScreen({super.key});
|
|
|
|
const DeckListScreen({super.key, this.showAppBar = true});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final bool showAppBar;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
State<DeckListScreen> createState() => DeckListScreenState();
|
|
|
|
State<DeckListScreen> createState() => DeckListScreenState();
|
|
|
|
@ -437,94 +439,8 @@ class DeckListScreenState extends State<DeckListScreen> {
|
|
|
|
_loadDecks();
|
|
|
|
_loadDecks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget _buildBody(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return _decks.isEmpty
|
|
|
|
return Scaffold(
|
|
|
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
|
|
|
title: Row(
|
|
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Image.asset(
|
|
|
|
|
|
|
|
'android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png',
|
|
|
|
|
|
|
|
height: 32,
|
|
|
|
|
|
|
|
width: 32,
|
|
|
|
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
|
|
|
|
errorBuilder: (_, __, ___) => Icon(
|
|
|
|
|
|
|
|
Icons.auto_stories,
|
|
|
|
|
|
|
|
size: 28,
|
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.primaryContainer,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
'omotomo',
|
|
|
|
|
|
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
|
|
|
|
|
|
fontWeight: FontWeight.w700,
|
|
|
|
|
|
|
|
letterSpacing: -0.5,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
actions: [
|
|
|
|
|
|
|
|
ValueListenableBuilder<ApiUser?>(
|
|
|
|
|
|
|
|
valueListenable: ApiAuthService.instance.currentUser,
|
|
|
|
|
|
|
|
builder: (context, user, _) {
|
|
|
|
|
|
|
|
return Row(
|
|
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
if (user != null) ...[
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(right: 4),
|
|
|
|
|
|
|
|
child: PopupMenuButton<void>(
|
|
|
|
|
|
|
|
offset: const Offset(0, 40),
|
|
|
|
|
|
|
|
tooltip: 'Account',
|
|
|
|
|
|
|
|
child: CircleAvatar(
|
|
|
|
|
|
|
|
radius: 18,
|
|
|
|
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
|
|
|
|
|
|
|
child: Text(
|
|
|
|
|
|
|
|
_userInitials(user),
|
|
|
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
|
|
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
itemBuilder: (context) => [
|
|
|
|
|
|
|
|
const PopupMenuItem<void>(
|
|
|
|
|
|
|
|
value: null,
|
|
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Icon(Icons.logout),
|
|
|
|
|
|
|
|
SizedBox(width: 12),
|
|
|
|
|
|
|
|
Text('Log out'),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
onSelected: (_) async {
|
|
|
|
|
|
|
|
await ApiAuthService.instance.logout();
|
|
|
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
|
|
|
|
|
|
Routes.login,
|
|
|
|
|
|
|
|
(route) => false,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
IconButton(
|
|
|
|
|
|
|
|
icon: const Icon(Icons.sync),
|
|
|
|
|
|
|
|
tooltip: 'Sync from server',
|
|
|
|
|
|
|
|
onPressed: () => _loadDecks(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
body: _decks.isEmpty
|
|
|
|
|
|
|
|
? Center(
|
|
|
|
? Center(
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
@ -727,7 +643,95 @@ class DeckListScreenState extends State<DeckListScreen> {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
|
|
final body = _buildBody(context);
|
|
|
|
|
|
|
|
if (!widget.showAppBar) {
|
|
|
|
|
|
|
|
return body;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
|
|
|
title: Row(
|
|
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Image.asset(
|
|
|
|
|
|
|
|
'android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png',
|
|
|
|
|
|
|
|
height: 32,
|
|
|
|
|
|
|
|
width: 32,
|
|
|
|
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
|
|
|
|
errorBuilder: (_, __, ___) => Icon(
|
|
|
|
|
|
|
|
Icons.auto_stories,
|
|
|
|
|
|
|
|
size: 28,
|
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.primaryContainer,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
|
|
|
'omotomo',
|
|
|
|
|
|
|
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
|
|
|
|
|
|
|
fontWeight: FontWeight.w700,
|
|
|
|
|
|
|
|
letterSpacing: -0.5,
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
actions: [
|
|
|
|
|
|
|
|
ValueListenableBuilder<ApiUser?>(
|
|
|
|
|
|
|
|
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 Row(
|
|
|
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
IconButton(
|
|
|
|
|
|
|
|
icon: const Icon(Icons.sync),
|
|
|
|
|
|
|
|
tooltip: 'Sync from server',
|
|
|
|
|
|
|
|
onPressed: () => _loadDecks(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
|
|
|
|
padding: const EdgeInsets.only(right: 4),
|
|
|
|
|
|
|
|
child: PopupMenuButton<String>(
|
|
|
|
|
|
|
|
offset: const Offset(0, 40),
|
|
|
|
|
|
|
|
tooltip: 'Account',
|
|
|
|
|
|
|
|
child: UserAvatar(user: user),
|
|
|
|
|
|
|
|
itemBuilder: (context) => [
|
|
|
|
|
|
|
|
const PopupMenuItem<String>(
|
|
|
|
|
|
|
|
value: 'logout',
|
|
|
|
|
|
|
|
child: Row(
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Icon(Icons.logout),
|
|
|
|
|
|
|
|
SizedBox(width: 12),
|
|
|
|
|
|
|
|
Text('Log out'),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
onSelected: (value) async {
|
|
|
|
|
|
|
|
if (value != 'logout') return;
|
|
|
|
|
|
|
|
final navigator = Navigator.of(context);
|
|
|
|
|
|
|
|
await ApiAuthService.instance.logout();
|
|
|
|
|
|
|
|
navigator.pushNamedAndRemoveUntil(
|
|
|
|
|
|
|
|
Routes.login,
|
|
|
|
|
|
|
|
(route) => false,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
body: body,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -767,6 +771,49 @@ class _StatChip extends StatelessWidget {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Shows profile image from [ApiUser.avatarUrl] when available, otherwise initials.
|
|
|
|
|
|
|
|
/// Public so HomeScreen can use the same avatar in the shared app bar.
|
|
|
|
|
|
|
|
class UserAvatar extends StatelessWidget {
|
|
|
|
|
|
|
|
const UserAvatar({super.key, required this.user});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ApiUser user;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
|
|
|
final initials = DeckListScreenState._userInitials(user);
|
|
|
|
|
|
|
|
final initialsWidget = Text(
|
|
|
|
|
|
|
|
initials,
|
|
|
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
|
|
|
color: theme.colorScheme.onPrimaryContainer,
|
|
|
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final url = user.avatarUrl?.trim();
|
|
|
|
|
|
|
|
if (url == null || url.isEmpty) {
|
|
|
|
|
|
|
|
return CircleAvatar(
|
|
|
|
|
|
|
|
radius: 18,
|
|
|
|
|
|
|
|
backgroundColor: theme.colorScheme.primaryContainer,
|
|
|
|
|
|
|
|
child: initialsWidget,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return CircleAvatar(
|
|
|
|
|
|
|
|
radius: 18,
|
|
|
|
|
|
|
|
backgroundColor: theme.colorScheme.primaryContainer,
|
|
|
|
|
|
|
|
child: ClipOval(
|
|
|
|
|
|
|
|
child: Image.network(
|
|
|
|
|
|
|
|
url,
|
|
|
|
|
|
|
|
width: 36,
|
|
|
|
|
|
|
|
height: 36,
|
|
|
|
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
|
|
|
|
errorBuilder: (_, __, ___) => initialsWidget,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _MockDataDialog extends StatefulWidget {
|
|
|
|
class _MockDataDialog extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
State<_MockDataDialog> createState() => _MockDataDialogState();
|
|
|
|
State<_MockDataDialog> createState() => _MockDataDialogState();
|
|
|
|
|