Flutter中createState返回类型不匹配及私有类型API问题求助
解决方法
先修正语法错误:你误将
createState方法写成了无括号的getter形式,正确的方法声明必须带括号:@override State<MyApp> createState() => _MyApp();确保私有类
_MyApp正确继承自State<MyApp>,整体代码结构要符合以下规范:class MyApp extends StatefulWidget { @override State<MyApp> createState() => _MyApp(); } class _MyApp extends State<MyApp> { // 在这里编写你的State逻辑代码 }
如果仍有报错,检查_MyApp的泛型参数是否和父Widget完全匹配——必须是State<MyApp>,不能绑定其他Widget类型。
内容的提问来源于stack exchange,提问作者David S
相关产品推荐
相关产品推荐

