gpt4 book ai didi

list - 为什么flutter返回类型 'List'不是 'List'的 'function result'类型的子类型?

转载 作者:行者123 更新时间:2023-12-03 03:33:08 25 4
gpt4 key购买 nike

我不明白为什么我不能打印列表中的元素。
并且总是返回“类型'列表'不是'函数结果'类型'列表'的子类型”

import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Generated App',
theme: ThemeData(
primarySwatch: Colors.blue,
primaryColor: const Color(0xFF2196f3),
accentColor: const Color(0xFF2196f3),
canvasColor: const Color(0xFFfafafa),
),
home: MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
var items = [1,2,3];

void main() {
if (true) {
print('hello, world!');
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('SingleChildScrollView'),
),
body: Column(
children: <Widget>[
Text(''),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () {
for (var i = 0; i < 3; i++) {
print(items[i]);
}
},
child: Icon(Icons.touch_app),
),
);
}
}
而且,如果我将“打印”部分更改为“字符串”,它将打印“I / chatty”,我不知道这是什么意思。
I/flutter (13445): items[i]
I/chatty (13445): uid=10155(com.example.flutterappse) Thread-2 identical 1 line
I/flutter (13445): items[i]
请让我知道原因以及解决方法。
谢谢!

最佳答案

Listint数据类型一起使用。

List<int> items = [1,2,3];

关于list - 为什么flutter返回类型 'List<dynamic>'不是 'List<int>'的 'function result'类型的子类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62611029/

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