Reputation: 1422
I am literally pulling my hair over this because all tutorials seem to be implementing this part of code this way.
But my compiler throws the error: The argument type 'BlocProvider' can't be assigned to the parameter type 'Widget'.
I am following the tutorial: Flutter Bloc & Cubit
All parts of the code work well apart from the Main.dart where we are supposed to add the BlocProvider
I am new to flutter and I have no Idea what I should do from here.
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: BlocProvider(
create: (context) => WeatherCubit(FakeWeatherRepository()),
child: WeatherSearchPage(),
),
);
}
}
The error is as seen in the attached image:
Upvotes: 1
Views: 1912
Reputation: 1422
If anyone ever experiences this error which is uncommon,
Run the following command: flutter pub cache repair
Then restart both the laptop and the IDE.
This worked for me following guidance by @felangel on github
Upvotes: 0
Reputation: 2678
I have mostly seen MaterialApp being the child of the BlocProvider, but this isn't the issue. I can't tell from the code shown, but my best guess is, you have a problem with FakeWeatherRepository
and WeatherSearchPage
, which may well cause the error of of BlocProvider not being a widget.
Are you sure both widgets are imported. The underline on the screens looks more like typo correction and not like error. But maybe you wand to remove BlocProvider and put both widgets behind home:
directly (either as a column or one by one) and check if they are recognized or if they still throw an error
Upvotes: 1