Flutter Base小部件和属性在所有项目中都是“未定义的”

ar5n3qh5  于 2023-05-19  发布在  Flutter
关注(0)|答案(3)|浏览(203)

我试图做一个弹出窗口,可以切换与浮动按钮,但现在我只是试图得到默认的例子工作。中心、列、方法和mainaxisalignment标识符(我想就是这个名字)突然停止工作了。我试图在一个文件中修复它,但我意识到它发生在我所有的文件中,甚至在不同的项目中。我是新的Flutter,所以我不知道我是否需要完全刷新我的系统,或者如果有一个特定的部分,我需要重新下载/刷新。任何帮助将不胜感激。谢谢大家。

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      // ERRORS HAPPEN IN THE FOLLOWING THREE LINES
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

这些是我得到的错误……

The method 'Center' isn't defined for the type '_MyHomePageState'.
Try correcting the name to the name of an existing method, or defining a method named 'Center'.dartundefined_method

The method 'Column' isn't defined for the type '_MyHomePageState'.
Try correcting the name to the name of an existing method, or defining a method named 'Column'.dartundefined_method

Undefined name 'MainAxisAlignment'.
Try correcting the name to one that is defined, or defining the name.dartundefined_identifier
ivqmmu1c

ivqmmu1c1#

1.先跑“扑干净”,然后“扑酒吧得到”。
1.如果仍然没有帮助,则检查Dart是否已启用。
1.如果仍然没有帮助,请单击无效缓存。

wmvff8tz

wmvff8tz2#

首先,尝试在项目根目录的终端中运行flutter pub get,看看它是否修复了问题。如果没有,并且您正在使用Android Studio,请尝试确保在项目设置中启用Dart,如果仍然从Android Studio文件菜单使该高速缓存无效并重新启动。

irtuqstp

irtuqstp3#

我能够解决这个问题

flutter upgrade      # download the new SDK for current channel

相关问题