Reputation: 117
I have fixed my first set of errors today, but now on this line the code breaks, and I can't figure this out
here is the bad line of code in queestion
builder: (BuildContext context) {... }
Here is the error:
Compiler message: lib/main.dart:11:5: Error: No named parameter with the name 'builder'. builder: (BuildContext context) { ^^^^^^^ ../../Downloads/flutter_windows_v1.12.13+hotfix.8-stable/src/flutter/.pub-cache/hosted/pub.dartlang.org/provider-4.0.4/lib/src/change_notifier_provider.dart:107:3: Context: Found this candidate, but the arguments don't match. ChangeNotifierProvider({ ^^^^^^^^^^^^^^^^^^^^^^ Target kernel_snapshot failed: Exception: Errors during snapshot creation: null build failed.
FAILURE: Build failed with an exception.
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'home_page.dart';
import 'auth.dart';
import 'login_page.dart';
void main() => runApp(
ChangeNotifierProvider<AuthService>(
child: MyApp(),
builder: (BuildContext context) {
return AuthService();
},
),
);
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: FutureBuilder<FirebaseUser>(
future: Provider.of<AuthService>(context).getUser(),
builder: (context, AsyncSnapshot<FirebaseUser> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
// log error to console
if (snapshot.error != null) {
print("error");
return Text(snapshot.error.toString());
}
// redirect to the proper page
return snapshot.hasData ? HomePage(snapshot.data) : LoginPage();
} else {
// show loading indicator
return LoadingCircle();
}
},
),
);
}
}
class LoadingCircle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Container(
child: CircularProgressIndicator(),
alignment: Alignment(0.0, 0.0),
),
);
}
Upvotes: 0
Views: 575
Reputation: 24691
ChangeNotifierProvider
does not have a builder
property. You want to use the create
property:
ChangeNotifierProvider<AuthService>(
create: (context) => AuthService(),
child: MyApp(),
},
Upvotes: 1