gpt4 book ai didi

dart - 使用 Targetplatform 导致布局问题

转载 作者:IT王子 更新时间:2023-10-29 07:12:37 25 4
gpt4 key购买 nike

我正在尝试检查用户使用的是 Iphone 还是 Android

我正在关注这个帖子以查看

How do you detect the host platform from Dart code?

在我的 initState 中,我添加了以下检查

typeOfDevice = Theme.of(context).platform == TargetPlatform.iOS
? "1"
: "2";

但每当我尝试使用它时,我都会收到以下错误

I/flutter (22330): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (22330): The following assertion was thrown building MediaQuery(MediaQueryData(size: Size(360.0, 640.0),
I/flutter (22330): devicePixelRatio: 2.0, textScaleFactor: 1.0, padding: EdgeInsets(0.0, 24.0, 0.0, 0.0), viewInsets:
I/flutter (22330): EdgeInsets.zero, alwaysUse24HourFormat: false, accessibleNavigation: falsedisableAnimations:
I/flutter (22330): falseinvertColors: falseboldText: false)):
I/flutter (22330): inheritFromWidgetOfExactType(_InheritedTheme) or inheritFromElement() was called before
I/flutter (22330): _EnterOtpLoginState.initState() completed.
I/flutter (22330): When an inherited widget changes, for example if the value of Theme.of() changes, its dependent
I/flutter (22330): widgets are rebuilt. If the dependent widget's reference to the inherited widget is in a constructor
I/flutter (22330): or an initState() method, then the rebuilt dependent widget will not reflect the changes in the
I/flutter (22330): inherited widget.
I/flutter (22330): Typically references to to inherited widgets should occur in widget build() methods. Alternatively,
I/flutter (22330): initialization based on inherited widgets can be placed in the didChangeDependencies method, which
I/flutter (22330): is called after initState and whenever the dependencies change thereafter.
I/flutter (22330): When the exception was thrown, this was the stack:
I/flutter (22330): #0 StatefulElement.inheritFromElement.<anonymous closure> (package:flutter/src/widgets/framework.dart:3920:9)
I/flutter (22330): #1 StatefulElement.inheritFromElement (package:flutter/src/widgets/framework.dart:3953:6)
I/flutter (22330): #2 Element.inheritFromWidgetOfExactType (package:flutter/src/widgets/framework.dart:3274:14)
I/flutter (22330): #3 Theme.of (package:flutter/src/material/theme.dart:127:52)
I/flutter (22330): #4 _EnterOtpLoginState.initState (package:dice_clutter/screens/otp_login/otp_login.dart:126:26)
I/flutter (22330): #5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3830:58)
I/flutter (22330): #6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #8 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
I/flutter (22330): #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #10 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
I/flutter (22330): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #14 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #15 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #16 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #17 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #18 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #19 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #20 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #21 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #22 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #23 ParentDataElement.mount (package:flutter/src/widgets/framework.dart:4047:11)
I/flutter (22330): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #25 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4965:32)
I/flutter (22330): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #31 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #35 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #36 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #37 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #44 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #45 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #47 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #48 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #49 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #50 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #51 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #52 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #53 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #54 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #55 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #56 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #57 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #58 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #59 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #60 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #61 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #62 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #63 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #64 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #65 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #66 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #67 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #68 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #69 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #70 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #71 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #72 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #73 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #74 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #75 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #76 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #77 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #78 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #79 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #80 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #81 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #82 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #83 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #84 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #85 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #86 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #87 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #88 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #89 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #90 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #91 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #92 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #93 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #94 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #95 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #96 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #97 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #98 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #99 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #100 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #101 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #102 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #103 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #104 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #105 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #106 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #107 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #108 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #109 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #110 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #111 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #112 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #113 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #114 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #115 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #116 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #117 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #118 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #119 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #120 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #121 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #122 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #123 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #124 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #125 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #126 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #127 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #128 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #129 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #130 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #131 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #132 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #133 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #134 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #135 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #136 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #137 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #138 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #139 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #140 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #141 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #142 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #143 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #144 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #145 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #146 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #147 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #148 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #149 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #150 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #151 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #152 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #153 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #154 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #155 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #156 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #157 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #158 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #159 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #160 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #161 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #162 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #163 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #164 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #165 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #166 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #167 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #168 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #169 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #170 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #171 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #172 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4860:14)
I/flutter (22330): #173 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #174 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #175 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #176 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #177 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #178 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #179 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #180 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #181 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #182 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #183 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #184 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #185 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #186 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #187 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #188 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #189 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #190 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3701:5)
I/flutter (22330): #191 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3848:11)
I/flutter (22330): #192 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3696:5)
I/flutter (22330): #193 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2950:14)
I/flutter (22330): #194 Element.updateChild (package:flutter/src/widgets/framework.dart:2753:12)
I/flutter (22330): #195 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4643:32)
I/flutter (22330): #196 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4975:17)
I/flutter (22330): #197 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #198 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:507:16)
I/flutter (22330): #199 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #200 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #201 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #202 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (22330): #203 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #204 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #205 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #206 ProxyElement.update (package:flutter/src/widgets/framework.dart:3990:5)
I/flutter (22330): #207 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #208 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (22330): #209 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #210 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #211 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #212 StatefulElement.update (package:flutter/src/widgets/framework.dart:3878:5)
I/flutter (22330): #213 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #214 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (22330): #215 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #216 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4867:14)
I/flutter (22330): #217 Element.updateChild (package:flutter/src/widgets/framework.dart:2742:15)
I/flutter (22330): #218 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3732:16)
I/flutter (22330): #219 Element.rebuild (package:flutter/src/widgets/framework.dart:3547:5)
I/flutter (22330): #220 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2286:33)
I/flutter (22330): #221 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:676:20)
I/flutter (22330): #222 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:219:5)
I/flutter (22330): #223 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (22330): #224 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (22330): #225 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (22330): #226 _invoke (dart:ui/hooks.dart:154:13)
I/flutter (22330): #227 _drawFrame (dart:ui/hooks.dart:143:3)
I/flutter (22330): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (22330): Another exception was thrown: The _ScaffoldLayout custom multichild layout delegate forgot to lay out the following child:
I/flutter (22330): Another exception was thrown: inheritFromWidgetOfExactType(_InheritedTheme) or inheritFromElement() was called before _EnterOtpLoginState.initState() completed.
I/flutter (22330): Another exception was thrown: The _ScaffoldLayout custom multichild layout delegate forgot to lay out the following children:

当我评论那行代码时应用运行良好

最佳答案

出现此问题是因为您试图从 initState 获取 Inheritedwidget。这是故意不可能的

改为使用didChangeDependencies:

didChangeDependencies() {
typeOfDevice = Theme.of(context).platform == TargetPlatform.iOS
}

关于dart - 使用 Targetplatform 导致布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54397665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com