Toy project to learn Flutter/Dart.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.0 KiB

import 'package:flutter/material.dart';
import 'package:swipe/utils.dart';
import 'package:provider/provider.dart';
import 'pokemon.dart';
import 'utils.dart';
// widget showing a list of all pokemons and their status to reach quickly an existing pokemon
class PokeList extends StatelessWidget {
const PokeList({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
PokemonProvider pP = Provider.of<PokemonProvider>(context);
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text("Liste"),
actions: [
IconButton(onPressed: () { pP.setSorting(Sort.alphabetic);}, icon: const Icon(Icons.sort_by_alpha)),
IconButton(onPressed: () { pP.setSorting(Sort.numerical);}, icon: const Icon(Icons.format_list_numbered)),
],
),
body: ListView.builder(itemBuilder: (_, int index) =>
GestureDetector(
key: Key(pP.index2str(index)),
child: Container(
child: Row(children: [
Image.asset(pP.index2mini(index)),
Text(pP.index2name(index), textScaleFactor: 1.5, style: const TextStyle(fontWeight: FontWeight.w400),),
Row(
children: [
Container(color: statusColor(pP.index2status(index)), width: 10, height: 10, margin: const EdgeInsets.symmetric(horizontal: 10)),
Text(pP.index2str(index)),
],
)
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
),
height: 50,
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(horizontal: 50),
padding: const EdgeInsets.symmetric(horizontal: 10),
),
onTap: () {
pP.setCurrentIndex(index);
Navigator.pushNamed(context, '/');
},
),
restorationId: pP.currentAsString(), // TODO fix position remember
itemCount: pP.pokemonNames.length,
)
);
}
}