refactor(presentation): main page as ConsumerWidget with nav provider

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Maxiwere45 2026-06-09 11:42:13 +02:00
parent 439c0101f4
commit d4c8936c80

View File

@ -1,46 +1,37 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../providers/navigation_provider.dart';
import 'pokemon_list.dart'; import 'pokemon_list.dart';
import 'guess_page.dart'; import 'guess_page.dart';
class MainPage extends StatefulWidget { class MainPage extends ConsumerWidget {
const MainPage({Key? key}) : super(key: key); const MainPage({Key? key}) : super(key: key);
@override static const List<Widget> _pages = [
State<MainPage> createState() => MainPageState(); PokemonListPage(),
} GuessPage(),
Center(child: Text("SYSTEM PAGE placeholder")),
class MainPageState extends State<MainPage> {
int _currentIndex = 0;
void setIndex(int index) {
setState(() {
_currentIndex = index;
});
}
final List<Widget> _pages = [
const PokemonListPage(),
const GuessPage(),
const Center(child: Text("SYSTEM PAGE placeholder")),
]; ];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context, WidgetRef ref) {
final currentIndex = ref.watch(selectedTabProvider);
return Scaffold( return Scaffold(
backgroundColor: const Color(0xFF1B2333), // Dark blue background behind the pokedex backgroundColor: const Color(0xFF1B2333),
body: SafeArea( body: SafeArea(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20.0), padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20.0),
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color(0xFFD32F2F), // Pokedex Red color: const Color(0xFFD32F2F),
borderRadius: BorderRadius.circular(30), borderRadius: BorderRadius.circular(30),
border: Border.all(color: const Color(0xFFA12020), width: 4), border: Border.all(color: const Color(0xFFA12020), width: 4),
), ),
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(26), borderRadius: BorderRadius.circular(26),
child: IndexedStack( child: IndexedStack(
index: _currentIndex, index: currentIndex,
children: _pages, children: _pages,
), ),
), ),
@ -53,28 +44,15 @@ class MainPageState extends State<MainPage> {
highlightColor: Colors.transparent, highlightColor: Colors.transparent,
), ),
child: BottomNavigationBar( child: BottomNavigationBar(
currentIndex: _currentIndex, currentIndex: currentIndex,
onTap: (index) { onTap: (index) => ref.read(selectedTabProvider.notifier).set(index),
setState(() {
_currentIndex = index;
});
},
type: BottomNavigationBarType.fixed, type: BottomNavigationBarType.fixed,
selectedItemColor: const Color(0xFFD32F2F), selectedItemColor: const Color(0xFFD32F2F),
unselectedItemColor: Colors.grey, unselectedItemColor: Colors.grey,
items: const [ items: const [
BottomNavigationBarItem( BottomNavigationBarItem(icon: Icon(Icons.grid_view), label: 'LIST'),
icon: Icon(Icons.grid_view), BottomNavigationBarItem(icon: Icon(Icons.games), label: 'GUESS'),
label: 'LIST', BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'SYSTEM'),
),
BottomNavigationBarItem(
icon: Icon(Icons.games),
label: 'GUESS',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'SYSTEM',
),
], ],
), ),
), ),