I am trying to update an old Flutter code, this is the original code:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: Auth(),
),
ChangeNotifierProxyProvider<Auth, Products>(
builder: (ctx, auth, previousProducts) => Products(
auth.token,
auth.userId,
previousProducts == null ? [] : previousProducts.items,
),
),
And I tried to modify it like below:
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider.value(
value: Auth(),
),
ChangeNotifierProxyProvider<Auth, Products>(
create: (ctx) => Products(),
update: (ctx, auth, previousProducts) => Products(
auth.token as String,
auth.userId as String,
previousProducts == null ? [] : previousProducts.items,
),
),
But still I have an error in the following line that I don't know how to resolve:
create: (ctx) => Products(),
3 positional argument(s) expected, but 0 found. Try adding the missing arguments.dartnot_enough_positional_arguments (new) Products Products( String authToken, String userId, List _items, )
And when I try to add arguments like what I passed in the update
part, it gives me different kind of other errors.
How should I renew this old code?