{"id":167249,"date":"2020-10-11T11:32:11","date_gmt":"2020-10-11T03:32:11","guid":{"rendered":"http:\/\/4563.org\/?p=167249"},"modified":"2020-10-11T11:32:11","modified_gmt":"2020-10-11T03:32:11","slug":"could-not-find-the-correct-provider-%e6%8a%a5%e9%94%99","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=167249","title":{"rendered":"Could not find the correct Provider \u62a5\u9519"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Could not find the correct Provider \u62a5\u9519               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Kaco <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4f7f\u7528\u7684\u662f Provider4.3.2<\/p>\n<p>\u6839\u636e\u6559\u7a0b\u5728 main \u4e2d\u5f15\u5165 Provider<\/p>\n<pre><code>void main() {   \/\/\u5f3a\u5236\u7ad6\u5c4f   WidgetsFlutterBinding.ensureInitialized();   SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])       .then((_) {     runApp(MultiProvider(       providers: [         ChangeNotifierProvider(create: (context) =&gt; Counter()),         ChangeNotifierProvider(create: (context) =&gt; CartProvider()),       ],       child: MyApp(),     ));   }); } <\/code><\/pre>\n<p>\u9996\u9875\u662f\u7528 PageView \u5207\u6362\u56db\u4e2a\u9875\u9762\u5206\u522b\u662f:\u9996\u9875-\u5206\u7c7b-\u8d2d\u7269\u8f66-\u6211\u7684 \u5728\u9996\u9875-\u5206\u7c7b \u4e0b\u4f7f\u7528<\/p>\n<pre><code>final counter = Provider.of&lt;Counter&gt;(context); <\/code><\/pre>\n<p>\u4f1a\u62a5\u9519 Error: Could not find the correct Provider&lt;Counter&gt; above this CategoryPage Widget<\/p>\n<p>\u800c \u8d2d\u7269\u8f66-\u6211\u7684 \u8fd9\u4e24\u4e2a\u9875\u9762\u5219\u4e0d\u4f1a\uff0c\u8fd9\u4e24\u4e2a\u9875\u9762\u662f\u7a7a\u767d\u7684,\u5c1d\u8bd5\u5427\u4ee3\u7801\u590d\u5236\u7ed9\u9996\u9875-\u5206\u7c7b\u90fd\u4f9d\u7136\u62a5\u9519<\/p>\n<pre><code>Widget build(BuildContext context) {     final counter = Provider.of&lt;Counter&gt;(context);     final cart = Provider.of&lt;CartProvider&gt;(context);      return Scaffold(       appBar: AppBar(         elevation: 0, \/\/ \u9690\u85cf\u9634\u5f71         title: Text(\"\u6211\u7684\"),       ),       body: Center(child: Text(\"${counter.count}\")),     );   } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3700505\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : kazeik <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u52a0\u4e2a\u53c2\u6570 listen:false \u8bd5\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3700506\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Kaco <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @kazeik \u6728\u6709\u7528&#8230;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Could not find th&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167249"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167249"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167249\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167249"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}