Error when calling stream using streamprovider - flutter

I am trying to use stream provider in my app, but it is returning an error when I invoke 'stream', telling me that 'the named parameter stream is not defined'. is this not the correct way to call it?
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
StreamProvider<FirebaseUser>.value(
stream: FirebaseAuth.instance.onAuthStateChanged),
],
child: MaterialApp(
title: 'Profile Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Profile'),
),
);
}
}

You likely changed from version 2 to 3.
The parameter got renamed:
StreamProvider.value(
value: myStream,
)

As the docs say, the property is called value, not stream
https://pub.dev/documentation/provider/latest/provider/StreamProvider/StreamProvider.value.html

Related

How to fix Navigator not working in flutter bloc pattern?

I am trying to make an application using Pokemon api as an exercise.
I am trying to make it using the Bloc pattern.
If you click on GridTile, you need to get indexID and move to DetailPage.
Getting the IndexID is fine, but it doesn't go to the page.
I can't seem to build the page, but I don't know what the problem is.
It would be really appreciated if you could tell me what the problem is.
I put the code on github because it would be good to see the whole code.
https://github.com/Jun-Kor/pokedex.git
The main problem is not your navigation, it's your Bloc, what happens is that when you enter the PokemonDetailsView page, with the BlocBuilder<PokemonDetailsBloc, PokemonDetailsState> it cannot find its provider (the one in the main) but, if we go directly there, you have it written, right ?
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
),
home: MultiBlocProvider( // here is the problem
providers: [
BlocProvider<PokemonBloc>(
create: (context) =>
PokemonBloc()..add(const PokemonPageRequestEvent(page: 0))),
BlocProvider<PokemonDetailsBloc>(
create: (context) => PokemonDetailsBloc()),
],
child: const PokedexView(),
),
);
}
}
Well, the MultiBlocProvider has to be the main parent that is going to provide for the whole MaterialApp, not be a child of it, I mean ? That's why the problem was asking for a Bloc provider, but I
it couldn't find one.
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return MultiBlocProvider( // change here
providers: [
BlocProvider<PokemonBloc>(
create: (context) =>
PokemonBloc()..add(const PokemonPageRequestEvent(page: 0))),
BlocProvider<PokemonDetailsBloc>(
create: (context) => PokemonDetailsBloc()),
],
child: MaterialApp(
title: 'Material App',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
),
home: const PokedexView(),
),
);
}
}

A product was used after being disposed once you have called dispose() on a product, it can no longer used

i am getting error after going back
A product was used after being disposed once you have called dispose() on a product, it can no longer used.
my code is written down
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import './screens/product_detail_screen.dart';
import './screens/products_overview_screen.dart';
import '/provider/products.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (ctx) => Products(),
child: MaterialApp(
title: 'Ram Shop',
theme: ThemeData(
primarySwatch: Colors.purple,
accentColor: Colors.deepOrange,
fontFamily: 'Lato',
),
home: ProductsOverviewScreen(),
routes: {
ProductDetailScreen.routeName: (ctx) => ProductDetailScreen(),
},
),
);
}
}
i tried searching for solution but didn't found any . please check my code and tell me what's wrong.

Debug mode banner is not removed

I am working on a Flutter app and want to hide the debug mode banner.
This is my code for main.dart:
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError;
//FirebaseCrashlytics.instance.crash();
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new MyApp(),
));
}
The debug mode banner is not removed, it is shown as always.
What do I need to change to get it removed?
Debug banner does not remove from main method, you just follow the example and you bind your MyApp() with the MaterialApp()
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: NextPage(),
);
}
}

Change application's starting dart file in flutter

I am new for flutter and I want to change the starting UI(interface). I tried to find out . but could not do it
Here the home: parameter specifies the starting page. If you want to change the page that will open at startup, you can give the name of the page you want instead of HomePage ().
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Time Tracker',
theme: ThemeData(
primarySwatch: Colors.indigo,
),
home: HomePage(),
debugShowCheckedModeBanner: false,
),
);
}
}
So:
home: HomePage(),
Change to:
home: AnythingPage()

Provider Error: Could not find the correct Provider<Color> above this MyApp Widget

I do not understand why the following code generates the error?
According to me the provider is an ancestor to MaterialApp and it should work? What am I missing?
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
new Provider<Color>(create: (_) => Colors.amber)
],
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Provider.of<Color>(context),
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
)
);
}
}
Provider initially in build method. You don't access to use provider value because provider inits context, but you tried to use provider.of(context) in the same place. If you use another state(view), you should use it.
Example code : https://gist.github.com/VB10/358dc944e5a86b58db2d898eaa1b5ea6