import 'package:flutter/material.dart';
import 'package:flutter_user_profile/home/parking_tile.dart';
import 'package:provider/provider.dart';
import 'parking_tile.dart';
import '../model/parking.dart';
class ParkingList extends StatefulWidget {
@override
State<ParkingList> createState() => _ParkingListState();
}
class _ParkingListState extends State<ParkingList> {
@override
Widget build(BuildContext context) {
final parkings = Provider.of<List<Parking>>(context);
return ListView.builder(
itemCount: parkings.length,
itemBuilder: (context,index){
return ParkingTile(parking: parkings[index]);
},
);
return Container();
}
}
And heres my coding for main.dart file
import 'package:flutter_user_profile/services/auth.dart';
import 'package:provider/provider.dart';
import 'package:flutter_user_profile/model/user.dart';
Future <void> main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: FirebaseOptions(apiKey: "AIzaSyD59Nz0y4Z8S-rVpeu5E5lslsW_8WYrEiE",
appId: "XXX", messagingSenderId: "XXX", projectId: "parkingtech-f1449") );
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context){
return StreamProvider<Client?>.value(
initialData: null,
value: AuthService().user,
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: Wrapper(),
)
);
}
}
when I run the app it could not find the correct provider and I’m not sure how to solve this,I’ve tried most of the solution but it seems that I still cant find the right way to do it. I’m still new to flutter please help
2
Answers
Have you registered this Parking in your main.dart ?
If didn’t, look at the mine answer.. Thanks
Error: Could not find the correct Provider<AppStateNotifier> above this Consumer<AppStateNotifier> Widget
You have to wrap you main app (parent class) with a provider (depending on the use case)!
Please check out the official documentation of Provider package to understand how to add a provider in the main app.
Link to the original package on pub: https://pub.dev/packages/provider
Example: https://pub.dev/packages/provider/example