gpt4 book ai didi

class - flutter 类不工作

转载 作者:IT王子 更新时间:2023-10-29 07:08:03 24 4
gpt4 key购买 nike

我是 Flutter/Dart 的新手,所以可能没有使用所有正确的关键字,但我遇到了一个问题,我在类 'FirstPageState' extends State 下得到了一条红线.这会阻止我调试应用程序,所以我来到这里希望能得到解决方案!

这是我的“FirstPage.dart”代码

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

String _FirstPageText = 'Exchange Rates';

class First extends StatefulWidget {
// This widget is the root of your application.
@override
FirstPageState createState() => new FirstPageState();
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text(_FirstPageText),
centerTitle: true,
backgroundColor: Colors.black,
),
body: new FeedWidget(),
),
);
}
}

class FirstPageState extends State<First> {

Future<String> getData() async {
var response = await http.get(
'https://jsonplaceholder.typicode.com/posts'
);

}

}

谢谢你:)

最佳答案

如果您阅读“红线”,您会看到一个错误,可能是 Statean abstract class期望 one or more methods to be defined :

Instance, getter, and setter methods can be abstract, defining an interface but leaving its implementation up to other classes

在这种情况下,我相信State expects the build method .你可能想看看 documentation behind StatefulWidget ,它描述了什么是必要的:

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

@override
_YellowBirdState createState() => new _YellowBirdState();
}

class _YellowBirdState extends State<YellowBird> {
@override
Widget build(BuildContext context) {
return new Container(color: const Color(0xFFFFE306));
}
}

关于class - flutter 类不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50650411/

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