Start to add entries
This commit is contained in:
parent
861848bf61
commit
c5cc8ed220
17 changed files with 372 additions and 123 deletions
151
lib/MainApp.dart
Normal file
151
lib/MainApp.dart
Normal file
|
@ -0,0 +1,151 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:libacflutter/Constants.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),
|
||||
),
|
||||
],
|
||||
),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
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),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue