whenever I add the provider to the MultipleProvider it just shows this weird error not not able to solve it after spending 4 hours.
main.dart
MultiProvider(
providers: [
Provider<HandleImageSelectionModel>(
create: (_) => HandleImageSelectionModel()),
],
child: MaterialApp(
title: 'Flutter Demo',
initialRoute: '/',
onGenerateRoute: RouteGenerator.generateRoute,
theme: ThemeData(
primarySwatch: Colors.blue,
),
),
);
Provider class
import 'package:flutter/foundation.dart';
class HandleImageSelectionModel extends ChangeNotifier {
bool isSelectionModeEnabled = false;
HandleImageSelectionModel();
toggleSelectionMode() {
isSelectionModeEnabled = !isSelectionModeEnabled;
notifyListeners();
}
}
Changing State
Provider.of<HandleImageSelectionModel>(context)
.toggleSelectionMode();
Trying to consume here
Consumer<HandleImageSelectionModel>(
builder: (context, isEnabled, child) {
print(isEnabled);
return Positioned(
child: Align(
alignment: Alignment.topRight,
child: CircularCheckBox(
value: true,
materialTapTargetSize:
MaterialTapTargetSize.padded,
onChanged: (bool x) {}),
),
);
},
)
You're using Provider
when the class you pass is a ChangeNotifier
.
Use ChangeNotifierProvider
instead:
ChangeNotifierProxyProvider<HandleImageSelectionModel>