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:
@@ -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.'),
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user