You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.0 KiB
108 lines
3.0 KiB
import 'package:flutter/material.dart';
|
|
|
|
import 'deck_list_screen.dart';
|
|
import 'community_decks_screen.dart';
|
|
|
|
/// Shell with tab navigation: My Decks and Community.
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
int _currentIndex = 0;
|
|
final GlobalKey<DeckListScreenState> _deckListKey = GlobalKey<DeckListScreenState>();
|
|
final GlobalKey<CommunityDecksScreenState> _communityKey = GlobalKey<CommunityDecksScreenState>();
|
|
|
|
void _onDestinationSelected(int index) {
|
|
if (index == _currentIndex) return;
|
|
setState(() => _currentIndex = index);
|
|
if (index == 0) {
|
|
_deckListKey.currentState?.refresh();
|
|
} else if (index == 2) {
|
|
_communityKey.currentState?.refresh();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: IndexedStack(
|
|
index: _currentIndex == 2 ? 1 : 0,
|
|
children: [
|
|
DeckListScreen(key: _deckListKey),
|
|
CommunityDecksScreen(key: _communityKey),
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () => _deckListKey.currentState?.showAddDeckOptions(),
|
|
tooltip: 'Add Deck',
|
|
child: const Icon(Icons.add),
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
bottomNavigationBar: BottomAppBar(
|
|
notchMargin: 8,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_NavItem(
|
|
icon: Icons.folder,
|
|
label: 'My Decks',
|
|
selected: _currentIndex == 0,
|
|
onTap: () => _onDestinationSelected(0),
|
|
),
|
|
const SizedBox(width: 56),
|
|
_NavItem(
|
|
icon: Icons.people,
|
|
label: 'Community',
|
|
selected: _currentIndex == 2,
|
|
onTap: () => _onDestinationSelected(2),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _NavItem extends StatelessWidget {
|
|
final IconData icon;
|
|
final String label;
|
|
final bool selected;
|
|
final VoidCallback onTap;
|
|
|
|
const _NavItem({
|
|
required this.icon,
|
|
required this.label,
|
|
required this.selected,
|
|
required this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return InkWell(
|
|
onTap: onTap,
|
|
customBorder: const CircleBorder(),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(icon, size: 22, color: selected ? Theme.of(context).colorScheme.primary : null),
|
|
const SizedBox(width: 6),
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: selected ? Theme.of(context).colorScheme.primary : null,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|