174 lines
4.6 KiB
Dart
174 lines
4.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:libacflutter/Constants.dart';
|
|
import 'package:pokedex/Consts.dart';
|
|
import 'package:pokedex/Session.dart';
|
|
import 'package:pokedex/pokemon.dart';
|
|
|
|
class MainApp extends StatefulWidget {
|
|
@override
|
|
_MainAppState createState() => _MainAppState();
|
|
}
|
|
|
|
class _MainAppState extends State<MainApp> {
|
|
void toggleTheme() {
|
|
setState(() {
|
|
SessionData.darkMode = !SessionData.darkMode;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'PokeDex',
|
|
theme: SessionData.darkMode ? ThemeData.dark() : ThemeData.light(),
|
|
routes: {
|
|
"/": (context) => Home(toggleTheme: toggleTheme),
|
|
"/dex": (context) => DexEntry(),
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class Home extends StatefulWidget {
|
|
final VoidCallback toggleTheme;
|
|
|
|
Home({required this.toggleTheme});
|
|
|
|
@override
|
|
_HomeState createState() => _HomeState();
|
|
}
|
|
|
|
class _HomeState extends State<Home> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('PokeDex'),
|
|
backgroundColor:
|
|
SessionData.darkMode
|
|
? LibACFlutterConstants.TITLEBAR_COLOR
|
|
: Colors.cyan,
|
|
actions: [
|
|
IconButton(
|
|
onPressed: widget.toggleTheme,
|
|
icon:
|
|
SessionData.darkMode
|
|
? Icon(Icons.sunny)
|
|
: Icon(Icons.mode_night),
|
|
),
|
|
],
|
|
),
|
|
drawer: Drawer(
|
|
elevation: 50,
|
|
child: Column(
|
|
children: [
|
|
DrawerHeader(
|
|
child: Column(
|
|
children: [
|
|
Text("PokeDex", style: TextStyle(fontSize: 24)),
|
|
Text(
|
|
"Version: ${Constants.VERSION}",
|
|
style: TextStyle(fontSize: 24),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
body: Padding(
|
|
padding: EdgeInsets.all(8),
|
|
child: GridView.builder(
|
|
itemBuilder: (builder, index) {
|
|
return Card(
|
|
elevation: 50,
|
|
color: Color.fromARGB(255, 194, 94, 0),
|
|
child: InkWell(
|
|
onTap: () {
|
|
Navigator.pushNamed(context, "/dex", arguments: index);
|
|
},
|
|
child: SizedBox(
|
|
width: 300,
|
|
height: 300,
|
|
child: Column(
|
|
children: [
|
|
Image.asset(
|
|
Pokemon.values[index].toDexPath(),
|
|
width: 198,
|
|
height: 198,
|
|
),
|
|
Text(
|
|
Pokemon.values[index].name,
|
|
style: TextStyle(fontSize: 32, color: Colors.black),
|
|
),
|
|
Text(
|
|
"#${Pokemon.values[index].id}",
|
|
style: TextStyle(fontSize: 24, color: Colors.black),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
itemCount: Pokemon.values.length,
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 4,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class DexEntry extends StatefulWidget {
|
|
@override
|
|
_DexEntryState createState() => _DexEntryState();
|
|
}
|
|
|
|
class _DexEntryState extends State<DexEntry> {
|
|
Pokemon _pkmn = Pokemon.Bulbasaur;
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
int index = ModalRoute.of(context)!.settings.arguments as int;
|
|
_pkmn = Pokemon.values[index];
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(_pkmn.name),
|
|
backgroundColor:
|
|
SessionData.darkMode
|
|
? LibACFlutterConstants.TITLEBAR_COLOR
|
|
: Colors.cyan,
|
|
),
|
|
body: Padding(
|
|
padding: EdgeInsets.all(8),
|
|
child: Column(
|
|
children: [
|
|
Image.asset(_pkmn.toDexPath()),
|
|
Text("ID: ${_pkmn.id}", style: TextStyle(fontSize: 24)),
|
|
Row(
|
|
children: [
|
|
Text("Type: ", style: TextStyle(fontSize: 24)),
|
|
_pkmn.getTypeWidgets(),
|
|
],
|
|
),
|
|
SizedBox(height: 24),
|
|
if (_pkmn.hasEvolutions)
|
|
Row(
|
|
children: [
|
|
Text("Evolutions: ", style: TextStyle(fontSize: 24)),
|
|
_pkmn.getEvolutions(0),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|