271 lines
7.8 KiB
Dart
271 lines
7.8 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:libacflutter/Constants.dart';
|
|
import 'package:pokedex/Consts.dart';
|
|
import 'package:pokedex/Session.dart';
|
|
import 'package:pokedex/UpdateCheck.dart';
|
|
import 'package:pokedex/filters.dart';
|
|
import 'package:pokedex/pokemon.dart';
|
|
import 'package:pokedex/pokemonHelpers.dart';
|
|
|
|
class MainApp extends StatefulWidget {
|
|
const MainApp({super.key});
|
|
|
|
@override
|
|
_MainAppState createState() => _MainAppState();
|
|
}
|
|
|
|
class _MainAppState extends State<MainApp> {
|
|
void toggleTheme() {
|
|
setState(() {
|
|
SessionData.darkMode = !SessionData.darkMode;
|
|
});
|
|
|
|
SessionData.finalize();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'PokeDex',
|
|
theme: SessionData.darkMode ? ThemeData.dark() : ThemeData.light(),
|
|
routes: {
|
|
"/": (context) => Home(toggleTheme: toggleTheme),
|
|
"/dex": (context) => DexEntry(),
|
|
"/filters": (context) => FilterPage(),
|
|
"/update": (context) => UpdateCheck(),
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
class Home extends StatefulWidget {
|
|
final VoidCallback toggleTheme;
|
|
|
|
const Home({super.key, required this.toggleTheme});
|
|
|
|
@override
|
|
_HomeState createState() => _HomeState();
|
|
}
|
|
|
|
class _HomeState extends State<Home> {
|
|
@override
|
|
void didChangeDependencies() {
|
|
SessionData.callbacks.mainPage = widget.toggleTheme;
|
|
SessionData.initialize();
|
|
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
SessionData.callbacks.mainPage = null;
|
|
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text("PokeDex - ${SessionData.highestGenID()} Entries"),
|
|
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 - ${SessionData.highestGenID()} Entries",
|
|
style: TextStyle(fontSize: 24),
|
|
),
|
|
Text(
|
|
"Version: ${Constants.VERSION}",
|
|
style: TextStyle(fontSize: 24),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
ListTile(
|
|
title: Text("Filters"),
|
|
leading: Icon(Icons.filter),
|
|
subtitle: Text("Opens the PokeDex filters"),
|
|
onTap: () async {
|
|
await Navigator.pushNamed(context, "/filters");
|
|
setState(() {});
|
|
},
|
|
),
|
|
if (Platform.isIOS || Platform.isAndroid)
|
|
ListTile(
|
|
title: Text("U P D A T E"),
|
|
subtitle: Text("Opens the update checker"),
|
|
leading: Icon(Icons.update),
|
|
onTap: () async {
|
|
await Navigator.pushNamed(context, "/update");
|
|
setState(() {});
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
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: () async {
|
|
await Navigator.pushNamed(context, "/dex", arguments: index);
|
|
setState(() {});
|
|
},
|
|
child: SizedBox(
|
|
width: 300,
|
|
height: 300,
|
|
child: Column(
|
|
children: [
|
|
Image.asset(
|
|
Pokemon.values[index].toDexPath(),
|
|
width: 64,
|
|
height: 64,
|
|
),
|
|
Text(
|
|
Pokemon.values[index].printName(proper: true),
|
|
style: TextStyle(fontSize: 16, color: Colors.black),
|
|
),
|
|
Text(
|
|
"#${Pokemon.values[index].id}",
|
|
style: TextStyle(fontSize: 16, color: Colors.black),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
itemCount: SessionData.highestGenID(),
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 3,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class DexEntry extends StatefulWidget {
|
|
const DexEntry({super.key});
|
|
|
|
@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];
|
|
|
|
SessionData.callbacks.dexDisplay = () async {
|
|
setState(() {});
|
|
};
|
|
|
|
super.didChangeDependencies();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
SessionData.callbacks.dexDisplay = null;
|
|
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(_pkmn.printName(proper: true)),
|
|
backgroundColor:
|
|
SessionData.darkMode
|
|
? LibACFlutterConstants.TITLEBAR_COLOR
|
|
: Colors.cyan,
|
|
),
|
|
body: Padding(
|
|
padding: EdgeInsets.all(8),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Center(child: Image.asset(_pkmn.toDexPath())),
|
|
Center(
|
|
child: Text(
|
|
"ID: ${_pkmn.pokeDexID}",
|
|
style: TextStyle(fontSize: 24),
|
|
),
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text("Type: ", style: TextStyle(fontSize: 24)),
|
|
PokemonHelpers.getTypeWidgets(_pkmn),
|
|
],
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"First Seen in Generation ${_pkmn.generation.name}",
|
|
style: TextStyle(fontSize: 24),
|
|
),
|
|
],
|
|
),
|
|
if (_pkmn.extraVariants.isNotEmpty)
|
|
Text("Extra Variations: ", style: TextStyle(fontSize: 24)),
|
|
if (_pkmn.extraVariants.isNotEmpty)
|
|
PokemonHelpers.getVariations(_pkmn),
|
|
|
|
SizedBox(height: 32),
|
|
SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: PokemonHelpers.getEvolutions(0, _pkmn),
|
|
),
|
|
),
|
|
if (SessionData.enableDescription && _pkmn.dexEntries.isNotEmpty)
|
|
Text("Description: ", style: TextStyle(fontSize: 24)),
|
|
if (SessionData.enableDescription && _pkmn.dexEntries.isNotEmpty)
|
|
PokemonHelpers.printDescription(_pkmn),
|
|
|
|
SizedBox(height: 50),
|
|
|
|
if (_pkmn.locations.isNotEmpty)
|
|
Text("Where to find:", style: TextStyle(fontSize: 24)),
|
|
if (_pkmn.locations.isNotEmpty)
|
|
PokemonHelpers.printLocations(_pkmn),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|