gpt4 book ai didi

dart - Flutter/Dart 错误 : Unexpected tag 0 (Nothing) in _MyAppState@16036154. 构建

转载 作者:IT王子 更新时间:2023-10-29 06:47:44 27 4
gpt4 key购买 nike

我在尝试遵循此 tutorial 时遇到了以下错误.奇怪的是,谷歌搜索此错误消息并没有得到任何有用的见解。

错误信息:

I/flutter ( 5472): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY 
╞═══════════════════════════════════════════════════════════
I/flutter ( 5472): The following _CompileTimeError was thrown building MyApp(dirty, state: _MyAppState#f8841):
I/flutter ( 5472): 'file:///Users/micah/MobileApps/flutter_test_1/lib/main.dart': error: Unexpected tag 0 (Nothing) in
I/flutter ( 5472): _MyAppState@16036154.build, expected a procedure, a constructor or a function node
I/flutter ( 5472):
I/flutter ( 5472): When the exception was thrown, this was the stack:
I/flutter ( 5472): #0 StatefulElement.build (package:flutter/src/widgets/framework.dart:3730:27)

ma​​in.dart 文件:

import 'package:flutter/material.dart';

// import './product_manager.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
// appBar: AppBar(
// title: Text('EasyList'),
// ),
// body: ProductManager(),
),
);
}
}

products.dart 文件:

import 'package:flutter/material.dart';

class Products extends StatelessWidget {
final List<String> products;

Products(this.products);

@override
Widget build(BuildContext context) {
return Column(
children: products
.map(
(element) => Card(
child: Column(
children: <Widget>[
Image.asset('assets/food.jpg'),
Text(element)
],
),
),
)
.toList()
);
}
}

product_manager.dart 文件:

import 'package:flutter/material.dart';

import './products.dart';

class ProductManager extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _ProductManagerState();
}
}

class _ProductManagerState extends State<ProductManager> {
List<String> _products = ['Food Tester'];

@override
Widget build(BuildContext context) {
return Column(
children: [
Container(
margin: EdgeInsets.all(10.0),
child: RaisedButton(
onPressed: () {
setState(() {
_products.add('Advanced Food Tester');
});
},
child: Text('Add Product'),
),
),
Products(_products)
],
);
}
}

最佳答案

单击“重新启动调试”修复了问题。

我认为问题可能与我从 StatefullWidget 更改为 StatelessWidget 而没有重新启动调试器有关。

关于dart - Flutter/Dart 错误 : Unexpected tag 0 (Nothing) in _MyAppState@16036154. 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51251050/

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