1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00

testing_app code review and improvements (#960)

This commit is contained in:
Miguel Beltran
2021-12-11 07:39:07 +01:00
committed by GitHub
parent 664b63c03c
commit ea624af0f9
4 changed files with 22 additions and 14 deletions

View File

@@ -7,7 +7,7 @@ import 'package:provider/provider.dart';
import 'package:testing_app/models/favorites.dart';
class FavoritesPage extends StatelessWidget {
static String routeName = '/favorites_page';
static const routeName = '/favorites_page';
const FavoritesPage({Key? key}) : super(key: key);
@@ -54,7 +54,7 @@ class FavoriteItemTile extends StatelessWidget {
key: Key('remove_icon_$itemNo'),
icon: const Icon(Icons.close),
onPressed: () {
Provider.of<Favorites>(context, listen: false).remove(itemNo);
context.read<Favorites>().remove(itemNo);
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Removed from favorites.'),

View File

@@ -8,7 +8,7 @@ import 'package:testing_app/models/favorites.dart';
import 'package:testing_app/screens/favorites.dart';
class HomePage extends StatelessWidget {
static String routeName = '/';
static const routeName = '/';
const HomePage({Key? key}) : super(key: key);
@@ -46,7 +46,7 @@ class ItemTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
var favoritesList = Provider.of<Favorites>(context);
final favoritesList = context.watch<Favorites>();
return Padding(
padding: const EdgeInsets.all(8.0),