为什么 htttp.get 在 Flutter 中给我一个错误

Why does htttp.get give me an Error in Flutter

我正在尝试从 Python 看起来像这样的脚本中获取值:

    from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/', methods = ['GET'])
def index():
    return jsonify({"greetings" : "Hi this is Python"})


if __name__ == '__main__':
    app.run(debug = True)

启动后我得到以下输出:

    C:\Users\finn1\PycharmProjects\FLASK_FLUTTER_APP\venv\Scripts\python.exe C:/Users/finn1/PycharmProjects/FLASK_FLUTTER_APP/main.py
 * Serving Flask app "main" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: ***-***-***
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

我是这样在 Flutter 中导入 http 库的:

import 'package:http/http.dart';

然后我尝试使用“http.get”获取数据:

child: IconButton(
                icon: new Icon(
                  Icons.settings,
                ),
                onPressed: () async {

                  final response = await http.get("http://127.0.0.1:5000/");

但是我在启动我的应用程序时遇到以下错误:

    Error: The getter 'http' isn't defined for the class '_HomepageState'.
 - '_HomepageState' is from 'package:what_todo/screens/homepage.dart' ('lib/screens/homepage.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'http'.
                      final response = await http.get("http://127.0.0.1:5000/");

感谢您的帮助!

尝试使用import 'package:http/http.dart' as http;

package example