Created
September 20, 2023 16:55
-
-
Save carloswm85/d2b8e2bb078af8c42acb8c74193bcd98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:miningtrackerapp/domain/entities/prueba.dart'; | |
| import 'package:miningtrackerapp/presentation/providers/pruebas/providers_pruebas.dart'; | |
| import 'package:miningtrackerapp/presentation/widgets/drawers/side_menu.dart'; | |
| import 'package:go_router/go_router.dart'; | |
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | |
| class TrackerHomeView extends ConsumerStatefulWidget { | |
| const TrackerHomeView({super.key}); | |
| @override | |
| TrackerHomeViewState createState() => TrackerHomeViewState(); | |
| } | |
| class TrackerHomeViewState extends ConsumerState<TrackerHomeView> { | |
| @override | |
| void initState() { | |
| super.initState(); | |
| //NOTE - Connection brigde for the UI to the DB | |
| ref.read(pruebasListProvider.notifier).loadPruebasList(); | |
| } | |
| //NOTE - build(BuildContext context) - RENDERING for the HomeScreen is done HERE | |
| @override | |
| Widget build(BuildContext context) { | |
| final scaffoldKey = GlobalKey<ScaffoldState>(); | |
| // //NOTE - initialLoading is true, the display | |
| // // THEY ARE ALREADY LOEADED IN THE PROVIDER | |
| final pruebasList = ref.watch(pruebasListProvider); | |
| // Progress indicator | |
| if (pruebasList.isEmpty) { | |
| return const Column( | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [Center(child: CircularProgressIndicator())]); | |
| } | |
| return Scaffold( | |
| key: scaffoldKey, | |
| appBar: AppBar( | |
| title: const Text('My App'), | |
| elevation: 5, | |
| actions: <Widget>[ | |
| IconButton( | |
| icon: const Icon(Icons.search_outlined), | |
| tooltip: 'Buscar información en las guías', | |
| onPressed: () { | |
| // final searchedMovies = ref.read(searchedMoviesProvider); | |
| // final searchedQuery = ref.read(searchQueryProvider); | |
| //NOTE - SHOW SEARCH | |
| // returns null when coming back using the arrow back icon | |
| // showSearch<Movie?>( | |
| // query: searchedQuery, | |
| // context: context, | |
| // delegate: SearchMovieDelegate( | |
| // initialMovies: searchedMovies, | |
| // searchMovies: ref | |
| // .read(searchedMoviesProvider.notifier) | |
| // .searchMoviesByQuery)) | |
| // .then((movie) { | |
| // if (movie == null) return; | |
| // //NOTE - On selected searched movie or CLOSE, return to MovieScreen | |
| // context.push('/movie/${movie.id}'); | |
| // }); | |
| //TODO - snackbar example | |
| // ScaffoldMessenger.of(context).showSnackBar( | |
| // const SnackBar(content: Text('This is a snackbar'))); | |
| }, | |
| ), | |
| ], | |
| ), | |
| // TUTORIAL - https://blog.logrocket.com/how-add-list-tile-flutter/ | |
| body: ListView.builder( | |
| itemCount: pruebasList.length, | |
| itemBuilder: (context, index) { | |
| final prueba = pruebasList[index]; | |
| final colors = Theme.of(context).colorScheme; | |
| // TODO - Dismissible: https://youtu.be/ZuEm-omgDjA | |
| return Card( | |
| margin: const EdgeInsets.all(2), | |
| child: ListTile( | |
| leading: CircleAvatar( | |
| child: Text( | |
| '${prueba.id}', | |
| ), | |
| ), | |
| title: Text('${prueba.nombre} ${prueba.apellido}'), | |
| subtitle: Text(prueba.email), | |
| isThreeLine: true, | |
| dense: false, | |
| trailing: IconButton( | |
| icon: const Icon(Icons.arrow_forward_ios_outlined), | |
| onPressed: () => context.push('/home/0/prueba/${prueba.id}'), | |
| ), | |
| onTap: () => context.push('/home/0/prueba/${prueba.id}'), | |
| onLongPress: () => context.push('/home/0/prueba/${prueba.id}'), | |
| enabled: prueba.nombre.length > 4 ? true : false, | |
| selected: prueba.nombre.length > 6 ? true : false, | |
| ), | |
| ); | |
| }, | |
| ), | |
| // NOTE - DRAWER | |
| drawer: SideMenu( | |
| scaffoldKey: scaffoldKey, | |
| )); | |
| } | |
| } | |
| //!SECTION - class _HomeViewState extends ConsumerState<_HomeView> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment