diff --git a/assets/sprites/dex/bulbasaur.png b/assets/sprites/dex/bulbasaur.png new file mode 100644 index 0000000..5f684d1 Binary files /dev/null and b/assets/sprites/dex/bulbasaur.png differ diff --git a/assets/sprites/dex/charizard.png b/assets/sprites/dex/charizard.png new file mode 100644 index 0000000..eb6e38b Binary files /dev/null and b/assets/sprites/dex/charizard.png differ diff --git a/assets/sprites/dex/charmander.png b/assets/sprites/dex/charmander.png new file mode 100644 index 0000000..ffac020 Binary files /dev/null and b/assets/sprites/dex/charmander.png differ diff --git a/assets/sprites/dex/charmeleon.png b/assets/sprites/dex/charmeleon.png new file mode 100644 index 0000000..8c5bcf0 Binary files /dev/null and b/assets/sprites/dex/charmeleon.png differ diff --git a/assets/sprites/dex/ivysaur.png b/assets/sprites/dex/ivysaur.png new file mode 100644 index 0000000..942667f Binary files /dev/null and b/assets/sprites/dex/ivysaur.png differ diff --git a/assets/sprites/dex/venusaur.png b/assets/sprites/dex/venusaur.png new file mode 100644 index 0000000..ab1e8b4 Binary files /dev/null and b/assets/sprites/dex/venusaur.png differ diff --git a/assets/sprites/gen1/bulbasaur.png b/assets/sprites/gen1/bulbasaur.png new file mode 100644 index 0000000..db3c636 Binary files /dev/null and b/assets/sprites/gen1/bulbasaur.png differ diff --git a/assets/sprites/gen1/charizard.png b/assets/sprites/gen1/charizard.png new file mode 100644 index 0000000..2f036cc Binary files /dev/null and b/assets/sprites/gen1/charizard.png differ diff --git a/assets/sprites/gen1/charmander.png b/assets/sprites/gen1/charmander.png new file mode 100644 index 0000000..0217282 Binary files /dev/null and b/assets/sprites/gen1/charmander.png differ diff --git a/assets/sprites/gen1/charmeleon.png b/assets/sprites/gen1/charmeleon.png new file mode 100644 index 0000000..2aced31 Binary files /dev/null and b/assets/sprites/gen1/charmeleon.png differ diff --git a/assets/sprites/gen1/ivysaur.png b/assets/sprites/gen1/ivysaur.png new file mode 100644 index 0000000..27bdd2a Binary files /dev/null and b/assets/sprites/gen1/ivysaur.png differ diff --git a/assets/sprites/gen1/venusaur.png b/assets/sprites/gen1/venusaur.png new file mode 100644 index 0000000..70e7a80 Binary files /dev/null and b/assets/sprites/gen1/venusaur.png differ diff --git a/lib/MainApp.dart b/lib/MainApp.dart new file mode 100644 index 0000000..e71363f --- /dev/null +++ b/lib/MainApp.dart @@ -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 { + 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 { + @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 { + 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), + ], + ), + ], + ), + ), + ); + } +} diff --git a/lib/Session.dart b/lib/Session.dart new file mode 100644 index 0000000..35e5842 --- /dev/null +++ b/lib/Session.dart @@ -0,0 +1,3 @@ +class SessionData { + static bool darkMode = false; +} diff --git a/lib/main.dart b/lib/main.dart index 7b7f5b6..f5e7e9e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,122 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:pokedex/MainApp.dart'; void main() { - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - // This widget is the root of your application. - @override - Widget build(BuildContext context) { - return MaterialApp( - title: 'Flutter Demo', - theme: ThemeData( - // This is the theme of your application. - // - // TRY THIS: Try running your application with "flutter run". You'll see - // the application has a purple toolbar. Then, without quitting the app, - // try changing the seedColor in the colorScheme below to Colors.green - // and then invoke "hot reload" (save your changes or press the "hot - // reload" button in a Flutter-supported IDE, or press "r" if you used - // the command line to start the app). - // - // Notice that the counter didn't reset back to zero; the application - // state is not lost during the reload. To reset the state, use hot - // restart instead. - // - // This works for code too, not just values: Most code changes can be - // tested with just a hot reload. - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), - ); - } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. - return Scaffold( - appBar: AppBar( - // TRY THIS: Try changing the color here to a specific color (to - // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar - // change color while the other colors stay the same. - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: Text(widget.title), - ), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - // - // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" - // action in the IDE, or press "p" in the console), to see the - // wireframe for each widget. - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text('You have pushed the button this many times:'), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - ); - } + runApp(MainApp()); } diff --git a/lib/pokemon.dart b/lib/pokemon.dart new file mode 100644 index 0000000..bc328a5 --- /dev/null +++ b/lib/pokemon.dart @@ -0,0 +1,202 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +enum Generation { + One, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine; + + toSpritePath() { + switch (this) { + case Generation.One: + return 'assets/sprites/gen1'; + case Generation.Two: + return 'assets/sprites/gen2'; + case Generation.Three: + return 'assets/sprites/gen3'; + case Generation.Four: + return 'assets/sprites/gen4'; + case Generation.Five: + return 'assets/sprites/gen5'; + case Generation.Six: + return 'assets/sprites/gen6'; + case Generation.Seven: + return 'assets/sprites/gen7'; + case Generation.Eight: + return 'assets/sprites/gen8'; + case Generation.Nine: + return 'assets/sprites/gen9'; + } + } +} + +enum Type { + Normal(Color.fromARGB(255, 192, 192, 192), Colors.black), + Fire(Color.fromARGB(255, 255, 0, 0), Colors.black), + Water(Color.fromARGB(255, 0, 174, 255), Colors.black), + Electric(Color(0xffFFD700), Colors.black), + Grass(Color.fromARGB(255, 0, 255, 0), Colors.black), + Ice(Color.fromARGB(255, 0, 255, 255), Colors.black), + Fighting(Color.fromARGB(255, 255, 0, 0), Colors.black), + Poison(Color.fromARGB(255, 128, 0, 128), Colors.black), + Ground(Color.fromARGB(255, 128, 126, 0), Colors.black), + Flying(Color.fromARGB(255, 128, 128, 255), Colors.black), + Psychic(Color.fromARGB(255, 255, 0, 255), Colors.black), + Bug(Color.fromARGB(255, 128, 128, 0), Colors.black), + Rock(Color.fromARGB(255, 128, 128, 128), Colors.black), + Ghost(Color.fromARGB(255, 128, 0, 128), Colors.black), + Dragon(Color.fromARGB(255, 85, 0, 102), Colors.black), + Dark(Color.fromARGB(255, 51, 51, 51), Colors.black), + Steel(Color.fromARGB(255, 192, 192, 192), Colors.black), + Fairy(Color.fromARGB(255, 255, 102, 255), Colors.black); + + final Color backgroundColor; + final Color textColor; + const Type(this.backgroundColor, this.textColor); +} + +class Evolution { + final int to; + final int level; + const Evolution(this.to, this.level); +} + +enum LearnType { TM, HM } + +enum Move { + Growl(LearnType.TM, Type.Normal, "Growl", 0, 100, 40), + Tackle(LearnType.TM, Type.Normal, "Tackle", 40, 100, 35), + VineWhip(LearnType.TM, Type.Grass, "Vine Whip", 45, 100, 25), + RazorLeaf(LearnType.TM, Type.Grass, "Razor Leaf", 55, 95, 25), + SolarBeam(LearnType.TM, Type.Grass, "Solar Beam", 120, 100, 10), + PoisonPowder(LearnType.TM, Type.Poison, "Poison Powder", 0, 75, 35), + SleepPowder(LearnType.TM, Type.Grass, "Sleep Powder", 0, 75, 15), + TakeDown(LearnType.TM, Type.Normal, "Take Down", 90, 85, 20), + DoubleEdge(LearnType.TM, Type.Normal, "Double-Edge", 120, 100, 15), + LeechSeed(LearnType.TM, Type.Grass, "Leech Seed", 0, 90, 10), + Growth(LearnType.TM, Type.Normal, "Growth", 0, 0, 20), + PoisonSting(LearnType.TM, Type.Poison, "Poison Sting", 15, 100, 35), + StringShot(LearnType.TM, Type.Bug, "String Shot", 0, 95, 40), + BugBite(LearnType.TM, Type.Bug, "Bug Bite", 60, 100, 20), + Confusion(LearnType.TM, Type.Psychic, "Confusion", 50, 100, 25); + + final LearnType type; + final Type moveType; + final String moveName; + final int power; + final int accuracy; + final int pp; + const Move( + this.type, + this.moveType, + this.moveName, + this.power, + this.accuracy, + this.pp, + ); +} + +enum Pokemon { + Bulbasaur(1, Generation.One, [Type.Grass, Type.Poison], Evolution(2, 16)), + Ivysaur(2, Generation.One, [Type.Grass, Type.Poison], Evolution(3, 32)), + Venusaur(3, Generation.One, [Type.Grass, Type.Poison], null), + Charmander(4, Generation.One, [Type.Fire], Evolution(5, 16)), + Charmeleon(5, Generation.One, [Type.Fire], Evolution(6, 36)), + Charizard(6, Generation.One, [Type.Fire, Type.Flying], null); + + final int id; + final Generation generation; + final List types; + final Evolution? evolution; + bool get hasEvolutions => evolution != null; + const Pokemon(this.id, this.generation, this.types, this.evolution); + + String toSpritePath() { + return '${generation.toSpritePath()}/${name.toLowerCase()}.png'; + } + + String toDexPath() { + return 'assets/sprites/dex/${name.toLowerCase()}.png'; + } + + String toSpriteShinyPath() { + return '${generation.toSpritePath()}/${name.toLowerCase()}_shiny.png'; + } + + Widget getTypeWidgets() { + List widgets = []; + for (Type type in types) { + widgets.add( + ElevatedButton( + onPressed: () {}, + style: ButtonStyle( + backgroundColor: WidgetStatePropertyAll(type.backgroundColor), + foregroundColor: WidgetStatePropertyAll(type.textColor), + ), + child: Text(type.name, style: TextStyle(fontSize: 24)), + ), + ); + } + return Row(children: widgets); + } + + Widget getEvolutions(int subID) { + if (!hasEvolutions) return Row(children: []); + + Pokemon ev = Pokemon.values.where((x) => x.id == evolution!.to).first; + + List sprites = []; + + if (subID == 0) { + sprites.add( + Column( + children: [ + Image.asset(toDexPath(), width: 96, height: 96), + getTypeWidgets(), + ], + ), + ); + sprites.add( + Column( + children: [ + Icon(Icons.arrow_forward, size: 48), + Text("Level ${evolution!.level}", style: TextStyle(fontSize: 24)), + ], + ), + ); + } + + sprites.add( + Column( + children: [ + Image.asset(ev.toDexPath(), width: 96, height: 96), + ev.getTypeWidgets(), + ], + ), + ); + + if (ev.hasEvolutions) { + sprites.add( + Column( + children: [ + Icon(Icons.arrow_forward, size: 48), + Text( + "Level ${ev.evolution!.level}", + style: TextStyle(fontSize: 24), + ), + ], + ), + ); + //sprites.add(Icon(Icons.arrow_forward, size: 48)); + sprites.add(ev.getEvolutions(subID + 1)); + } + + return Row(children: sprites); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 1026100..11fa30f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: pokedex description: "A PokeDex!" # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -57,16 +57,25 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg + assets: + - assets/sprites/gen1/bulbasaur.png + - assets/sprites/dex/bulbasaur.png + - assets/sprites/dex/ivysaur.png + - assets/sprites/gen1/ivysaur.png + - assets/sprites/dex/venusaur.png + - assets/sprites/gen1/venusaur.png + - assets/sprites/dex/charmander.png + - assets/sprites/gen1/charmander.png + - assets/sprites/dex/charmeleon.png + - assets/sprites/gen1/charmeleon.png + - assets/sprites/dex/charizard.png + - assets/sprites/gen1/charizard.png # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/to/resolution-aware-images