@@ -20,7 +20,6 @@ import 'package:firebase_core/firebase_core.dart';
2020import 'package:firebase_performance/firebase_performance.dart' ;
2121import 'package:flutter/material.dart' ;
2222import 'package:performance_quickstart/firebase_status.dart' ;
23- import 'package:provider/provider.dart' ;
2423import 'package:http/http.dart' as http;
2524import 'package:url_launcher/url_launcher.dart' ;
2625
@@ -29,14 +28,13 @@ import './firebase_options.dart';
2928void main () {
3029 WidgetsFlutterBinding .ensureInitialized ();
3130
32- runApp (ChangeNotifierProvider (
33- create: (context) => ApplicationState (),
34- builder: (context, child) => const MyApp (),
35- ));
31+ runApp (MyApp (state: ApplicationState ()));
3632}
3733
3834class MyApp extends StatelessWidget {
39- const MyApp ({super .key});
35+ const MyApp ({super .key, required this .state});
36+
37+ final ApplicationState state;
4038
4139 // This widget is the root of your application.
4240 @override
@@ -55,15 +53,16 @@ class MyApp extends StatelessWidget {
5553 // is not restarted.
5654 primarySwatch: Colors .blue,
5755 ),
58- home: const MyHomePage (title: 'Firebase Performance Monitoring' ),
56+ home: MyHomePage (title: 'Firebase Performance Monitoring' , state : state ),
5957 );
6058 }
6159}
6260
6361class MyHomePage extends StatelessWidget {
64- const MyHomePage ({super .key, required this .title});
62+ const MyHomePage ({super .key, required this .title, required this .state });
6563
6664 final String title;
65+ final ApplicationState state;
6766
6867 @override
6968 Widget build (BuildContext context) {
@@ -72,27 +71,29 @@ class MyHomePage extends StatelessWidget {
7271 title: Text (title),
7372 ),
7473 body: Center (
75- child: Consumer <ApplicationState >(
76- builder: (context, appState, _) => Column (
74+ child: ListenableBuilder
75+ (
76+ listenable: state,
77+ builder: (context, child) => Column (
7778 children: < Widget > [
7879 const Image (
7980 image:
8081 AssetImage ('assets/perfmon_horizonal_lockup_light.png' )),
8182 const Text ('We are using Performance monitoring to monitor a '
8283 'function that gets a random string.' ),
8384 ElevatedButton (
84- onPressed: () => {appState .updateRandomString ()},
85+ onPressed: () => {state .updateRandomString ()},
8586 child: const Text ('Get Random String' ),
8687 ),
87- Text (appState .randomString),
88+ Text (state .randomString),
8889 ElevatedButton (
89- onPressed: () => {appState .getFirebaseStatus ()},
90+ onPressed: () => {state .getFirebaseStatus ()},
9091 child: const Text ('Get Firebase Status' ),
9192 ),
9293 InkWell (
93- child: Text (appState .lastIncident),
94- onTap: () => appState
95- ._launchInWebViewOrVC (Uri .parse (appState .lastIncidentUri)),
94+ child: Text (state .lastIncident),
95+ onTap: () => state
96+ ._launchInWebViewOrVC (Uri .parse (state .lastIncidentUri)),
9697 )
9798 ],
9899 ),
0 commit comments