質問編集履歴

2

書式の改善

2020/07/31 23:55

投稿

kazuki_user
kazuki_user

スコア147

test CHANGED
File without changes
test CHANGED
@@ -194,66 +194,4 @@
194
194
 
195
195
  - You used a `BuildContext` that is an ancestor of the provider you are trying to read.
196
196
 
197
-
198
-
199
- Make sure that Consumer<BookListModel> is under your MultiProvider/Provider<BookListModel>.
200
-
201
- This usually happen when you are creating a provider and trying to read it immediatly.
202
-
203
-
204
-
205
- For example, instead of:
206
-
207
-
208
-
209
- ```
210
-
211
- Widget build(BuildContext context) {
212
-
213
- return Provider<Example>(
214
-
215
- create: (_) => Example(),
216
-
217
- // Will throw a ProviderNotFoundError, because `context` is associated
218
-
219
- // to the widget that is the parent of `Provider<Example>`
220
-
221
- child: Text(context.watch<Example>()),
222
-
223
- ),
224
-
225
- }
226
-
227
- ```
228
-
229
-
230
-
231
- consider using `builder` like so:
232
-
233
-
234
-
235
- ```
236
-
237
- Widget build(BuildContext context) {
238
-
239
- return Provider<Example>(
240
-
241
- create: (_) => Example(),
242
-
243
- // we use `builder` to obtain a new `BuildContext` that has access to the provider
244
-
245
- builder: (context) {
246
-
247
- // No longer throws
248
-
249
- return Text(context.watch<Example>()),
250
-
251
- }
252
-
253
- ),
254
-
255
- }
256
-
257
- ```
258
-
259
197
  ```

1

書式の改善

2020/07/31 23:55

投稿

kazuki_user
kazuki_user

スコア147

test CHANGED
File without changes
test CHANGED
@@ -159,3 +159,101 @@
159
159
  }
160
160
 
161
161
  ```
162
+
163
+
164
+
165
+ ---
166
+
167
+
168
+
169
+ エラー全文です????
170
+
171
+
172
+
173
+ ```error
174
+
175
+ Error: Could not find the correct Provider<BookListModel> above this Consumer<BookListModel> Widget
176
+
177
+
178
+
179
+ This likely happens because you used a `BuildContext` that does not include the provider
180
+
181
+ of your choice. There are a few common scenarios:
182
+
183
+
184
+
185
+ - The provider you are trying to read is in a different route.
186
+
187
+
188
+
189
+ Providers are "scoped". So if you insert of provider inside a route, then
190
+
191
+ other routes will not be able to access that provider.
192
+
193
+
194
+
195
+ - You used a `BuildContext` that is an ancestor of the provider you are trying to read.
196
+
197
+
198
+
199
+ Make sure that Consumer<BookListModel> is under your MultiProvider/Provider<BookListModel>.
200
+
201
+ This usually happen when you are creating a provider and trying to read it immediatly.
202
+
203
+
204
+
205
+ For example, instead of:
206
+
207
+
208
+
209
+ ```
210
+
211
+ Widget build(BuildContext context) {
212
+
213
+ return Provider<Example>(
214
+
215
+ create: (_) => Example(),
216
+
217
+ // Will throw a ProviderNotFoundError, because `context` is associated
218
+
219
+ // to the widget that is the parent of `Provider<Example>`
220
+
221
+ child: Text(context.watch<Example>()),
222
+
223
+ ),
224
+
225
+ }
226
+
227
+ ```
228
+
229
+
230
+
231
+ consider using `builder` like so:
232
+
233
+
234
+
235
+ ```
236
+
237
+ Widget build(BuildContext context) {
238
+
239
+ return Provider<Example>(
240
+
241
+ create: (_) => Example(),
242
+
243
+ // we use `builder` to obtain a new `BuildContext` that has access to the provider
244
+
245
+ builder: (context) {
246
+
247
+ // No longer throws
248
+
249
+ return Text(context.watch<Example>()),
250
+
251
+ }
252
+
253
+ ),
254
+
255
+ }
256
+
257
+ ```
258
+
259
+ ```