The following code is to open a new customer adding widget.
final newOrderIdScopedProvider = Provider.autoDispose<int>((ref) {
ref.onDispose(() {
debugPrint('newOrderIdScopedProvider of value ${ref.state} has been disposed');
});
throw UnimplementedError('newOrderIdScopedProvider has not been initialized');
});
Navigator.of(context).push(
HeroDialogRoute(
builder: (_) => ProviderScope(
overrides: [
newOrderIdScopedProvider.overrideWithValue(orderId),
],
child: const AddNewCustomerWidget(),
),
),
);
The newOrderIdScopedProvider
has been overriden for this page as it may be opened from different places with different orderIds
Now look at the AddNewCustomerWidget
SizedBox(
width: 1100,
height: 600,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Scaffold(
key: addNewCustomerNotifier.scaffoldKey,
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(
width: 1100,
height: 600,
child: Column(
children: const [
AddNewCustomerHeader(),
AddNewCustomerTextField(),
VerticalSpacer(height: 10),
Divider(),
AddNewCustomerTabsWidget(),
AddNewCustomerTabsView(),
],
),
),
),
),
),
),
);
The problem is that from inside the build method of the AddNewCustomerWidget
, the newOrderIdScopedProvider
can be read and everything is ok.
But,
when I try to read the newOrderIdScopedProvider
from inside the build methods of the children like AddNewCustomerHeader()
or AddNewCustomerTextField()
or anyone,
I get the error message that the newOrderIdScopedProvider
has not been Initialized.
Why is this happenning?