class - flutter 类不工作

标签 class dart widget flutter

我是 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/

相关文章:

java - 使用 JButton 通过 addActionListener 处理 JFrame

时间:2018-03-08 标签:c++classesswitchcase

dart - Flutter 中的路由守卫

flutter - 从 Flutter 中的 Stateful Widget 返回数据

python - 类变量的 setter

c++ - (C++) 为什么 boost 作者在这里使用结构而不是类?

dart - 如何将包含 url 的文本绑定(bind)为 html

android-studio - flutter 控制台日志 "Failed to send request: {"jsonrpc":"2.0","id":"9354","method":"getVM","params":{}}"

Android Widget 显示错误并且 updateAppWidget 找不到任何 View

javascript - 外部小部件加载完成时执行 JS 命令