Add a handler for the filters on evolutions.
This commit is contained in:
parent
3f4462435b
commit
670c23d264
6 changed files with 94 additions and 52 deletions
|
@ -1,7 +1,7 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
class Constants {
|
class Constants {
|
||||||
static const VERSION = "1.0.032325+2027";
|
static const VERSION = "1.0.032325+2236";
|
||||||
|
|
||||||
static bool get isMobile => Platform.isAndroid || Platform.isIOS;
|
static bool get isMobile => Platform.isAndroid || Platform.isIOS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class _HomeState extends State<Home> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('PokeDex'),
|
title: Text("PokeDex - ${SessionData.highestGenID()} Entries"),
|
||||||
backgroundColor:
|
backgroundColor:
|
||||||
SessionData.darkMode
|
SessionData.darkMode
|
||||||
? LibACFlutterConstants.TITLEBAR_COLOR
|
? LibACFlutterConstants.TITLEBAR_COLOR
|
||||||
|
@ -69,7 +69,10 @@ class _HomeState extends State<Home> {
|
||||||
DrawerHeader(
|
DrawerHeader(
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Text("PokeDex", style: TextStyle(fontSize: 24)),
|
Text(
|
||||||
|
"PokeDex - ${SessionData.highestGenID()} Entries",
|
||||||
|
style: TextStyle(fontSize: 24),
|
||||||
|
),
|
||||||
Text(
|
Text(
|
||||||
"Version: ${Constants.VERSION}",
|
"Version: ${Constants.VERSION}",
|
||||||
style: TextStyle(fontSize: 24),
|
style: TextStyle(fontSize: 24),
|
||||||
|
@ -81,8 +84,9 @@ class _HomeState extends State<Home> {
|
||||||
title: Text("Filters"),
|
title: Text("Filters"),
|
||||||
leading: Icon(Icons.filter),
|
leading: Icon(Icons.filter),
|
||||||
subtitle: Text("Opens the PokeDex filters"),
|
subtitle: Text("Opens the PokeDex filters"),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
Navigator.pushNamed(context, "/filters");
|
await Navigator.pushNamed(context, "/filters");
|
||||||
|
setState(() {});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -96,8 +100,9 @@ class _HomeState extends State<Home> {
|
||||||
elevation: 50,
|
elevation: 50,
|
||||||
color: Color.fromARGB(255, 194, 94, 0),
|
color: Color.fromARGB(255, 194, 94, 0),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
Navigator.pushNamed(context, "/dex", arguments: index);
|
await Navigator.pushNamed(context, "/dex", arguments: index);
|
||||||
|
setState(() {});
|
||||||
},
|
},
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 300,
|
width: 300,
|
||||||
|
@ -129,7 +134,7 @@ class _HomeState extends State<Home> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
itemCount: Pokemon.values.length,
|
itemCount: SessionData.highestGenID(),
|
||||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
crossAxisCount: Constants.isMobile ? 3 : 4,
|
crossAxisCount: Constants.isMobile ? 3 : 4,
|
||||||
),
|
),
|
||||||
|
|
|
@ -1,6 +1,39 @@
|
||||||
import 'package:pokedex/filters.dart';
|
import 'package:pokedex/filters.dart';
|
||||||
|
import 'package:pokedex/pokemon.dart';
|
||||||
|
|
||||||
class SessionData {
|
class SessionData {
|
||||||
static bool darkMode = false;
|
static bool darkMode = false;
|
||||||
static int filter = Filters.All;
|
static int highest = 9;
|
||||||
|
static int _cachedHighest = -1;
|
||||||
|
|
||||||
|
static void resetHighestGenCache() {
|
||||||
|
_cachedHighest = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int highestGenID() {
|
||||||
|
if (_cachedHighest != -1) return _cachedHighest;
|
||||||
|
List<Generation> gens = [];
|
||||||
|
|
||||||
|
if (highest >= 9) gens.add(Generation.Nine);
|
||||||
|
if (highest >= 8) gens.add(Generation.Eight);
|
||||||
|
if (highest >= 7) gens.add(Generation.Seven);
|
||||||
|
if (highest >= 6) gens.add(Generation.Six);
|
||||||
|
if (highest >= 5) gens.add(Generation.Five);
|
||||||
|
if (highest >= 4) gens.add(Generation.Four);
|
||||||
|
if (highest >= 3) gens.add(Generation.Three);
|
||||||
|
if (highest >= 2) gens.add(Generation.Two);
|
||||||
|
if (highest >= 1) gens.add(Generation.One);
|
||||||
|
|
||||||
|
int max = 0;
|
||||||
|
// Iterate over the list, and get the count of all pokemon from a specific generation
|
||||||
|
for (var gen in gens) {
|
||||||
|
for (var pokemon in Pokemon.values) {
|
||||||
|
if (pokemon.generation == gen) max++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_cachedHighest = max;
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,21 +3,6 @@ import 'package:flutter/widgets.dart';
|
||||||
import 'package:libacflutter/Constants.dart';
|
import 'package:libacflutter/Constants.dart';
|
||||||
import 'package:pokedex/Session.dart';
|
import 'package:pokedex/Session.dart';
|
||||||
|
|
||||||
class Filters {
|
|
||||||
static final int GEN1 = 1;
|
|
||||||
static final int GEN2 = 2;
|
|
||||||
static final int GEN3 = 4;
|
|
||||||
static final int GEN4 = 8;
|
|
||||||
static final int GEN5 = 16;
|
|
||||||
static final int GEN6 = 32;
|
|
||||||
static final int GEN7 = 64;
|
|
||||||
static final int GEN8 = 128;
|
|
||||||
static final int GEN9 = 255;
|
|
||||||
|
|
||||||
static final int All =
|
|
||||||
GEN1 | GEN2 | GEN3 | GEN4 | GEN5 | GEN6 | GEN7 | GEN8 | GEN9;
|
|
||||||
}
|
|
||||||
|
|
||||||
class FilterPage extends StatefulWidget {
|
class FilterPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
State<StatefulWidget> createState() {
|
||||||
|
@ -46,92 +31,101 @@ class _filterPage extends State<FilterPage> {
|
||||||
style: TextStyle(fontSize: 24),
|
style: TextStyle(fontSize: 24),
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN1 == Filters.GEN1),
|
value: (SessionData.highest >= 1),
|
||||||
title: Text("Generation 1"),
|
title: Text("Generation 1"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN1;
|
SessionData.highest = 1;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN2 == Filters.GEN2),
|
value: (SessionData.highest >= 2),
|
||||||
title: Text("Generation 2"),
|
title: Text("Generation 2"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN2;
|
SessionData.highest = 2;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN3 == Filters.GEN3),
|
value: (SessionData.highest >= 3),
|
||||||
title: Text("Generation 3"),
|
title: Text("Generation 3"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN3;
|
SessionData.highest = 3;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN4 == Filters.GEN4),
|
value: (SessionData.highest >= 4),
|
||||||
title: Text("Generation 4"),
|
title: Text("Generation 4"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN4;
|
SessionData.highest = 4;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN5 == Filters.GEN5),
|
value: (SessionData.highest >= 5),
|
||||||
title: Text("Generation 5"),
|
title: Text("Generation 5"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN5;
|
SessionData.highest = 5;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN6 == Filters.GEN6),
|
value: (SessionData.highest >= 6),
|
||||||
title: Text("Generation 6"),
|
title: Text("Generation 6"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN6;
|
SessionData.highest = 6;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN7 == Filters.GEN7),
|
value: (SessionData.highest >= 7),
|
||||||
title: Text("Generation 7"),
|
title: Text("Generation 7"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN7;
|
SessionData.highest = 7;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN8 == Filters.GEN8),
|
value: (SessionData.highest >= 8),
|
||||||
title: Text("Generation 8"),
|
title: Text("Generation 8"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN8;
|
SessionData.highest = 8;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
value: (SessionData.filter & Filters.GEN9 == Filters.GEN9),
|
value: (SessionData.highest >= 9),
|
||||||
title: Text("Generation 9"),
|
title: Text("Generation 9"),
|
||||||
|
|
||||||
onChanged: (val) {
|
onChanged: (val) {
|
||||||
setState(() {
|
setState(() {
|
||||||
SessionData.filter = SessionData.filter ^ Filters.GEN9;
|
SessionData.highest = 9;
|
||||||
|
SessionData.resetHighestGenCache();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:pokedex/Consts.dart';
|
import 'package:pokedex/Consts.dart';
|
||||||
|
import 'package:pokedex/Session.dart';
|
||||||
|
|
||||||
enum Generation {
|
enum Generation {
|
||||||
One(1, 151),
|
One(1, 151),
|
||||||
|
@ -379,6 +380,8 @@ enum Pokemon {
|
||||||
null,
|
null,
|
||||||
previousPokemon: 21,
|
previousPokemon: 21,
|
||||||
),
|
),
|
||||||
|
Ekans(23, Generation.One, [Type.Poison], SingleEvolution(24, 22)),
|
||||||
|
Arbok(24, Generation.One, [Type.Poison], null, previousPokemon: 23),
|
||||||
Pikachu(
|
Pikachu(
|
||||||
25,
|
25,
|
||||||
Generation.One,
|
Generation.One,
|
||||||
|
@ -868,25 +871,32 @@ enum Pokemon {
|
||||||
|
|
||||||
List<Pokemon> Evs = [];
|
List<Pokemon> Evs = [];
|
||||||
|
|
||||||
if (previousPokemon != -1 && subID == 0) {
|
// ID must be in inclusive range of 1...MAXGeneration
|
||||||
Pokemon pkmn = Pokemon.values.where((x) => x.id == previousPokemon).first;
|
if (previousPokemon != -1 &&
|
||||||
return pkmn.getEvolutions(0);
|
previousPokemon <= SessionData.highestGenID()) {
|
||||||
|
if (previousPokemon != -1 && subID == 0) {
|
||||||
|
Pokemon pkmn =
|
||||||
|
Pokemon.values.where((x) => x.id == previousPokemon).first;
|
||||||
|
return pkmn.getEvolutions(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//print("Processing evolutions for ${pokemonName}");
|
//print("Processing evolutions for ${pokemonName}");
|
||||||
|
|
||||||
if (evolution is SingleEvolution) {
|
if (evolution is SingleEvolution) {
|
||||||
//print("Single Evolution identified");
|
//print("Single Evolution identified");
|
||||||
Evs.add(
|
var pokemon =
|
||||||
Pokemon.values
|
Pokemon.values
|
||||||
.where((x) => x.id == (evolution! as SingleEvolution).to)
|
.where((x) => x.id == (evolution! as SingleEvolution).to)
|
||||||
.first,
|
.first;
|
||||||
);
|
|
||||||
|
if (pokemon.id <= SessionData.highestGenID()) Evs.add(pokemon);
|
||||||
} else {
|
} else {
|
||||||
//print("Branching Evolution identified");
|
//print("Branching Evolution identified");
|
||||||
// Handle branched evolutions. Refactor below to accomodate a list of pokemon.
|
// Handle branched evolutions. Refactor below to accomodate a list of pokemon.
|
||||||
for (var ev in (evolution! as BranchedEvolution).alternates) {
|
for (var ev in (evolution! as BranchedEvolution).alternates) {
|
||||||
Evs.add(Pokemon.values.where((x) => x.id == ev).first);
|
var pokemon = Pokemon.values.where((x) => x.id == ev).first;
|
||||||
|
if (pokemon.id <= SessionData.highestGenID()) Evs.add(pokemon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
|
||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.0.032325+2027
|
version: 1.0.032325+2236
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.7.0
|
sdk: ^3.7.0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue