I was trying to make a popup that could toggle with the floating button but now I am just trying to get the default example working. The center, column, methods and mainaxisalignment identifier(I think that is the name) suddenly stopped working. I was trying to fix it in one file but I realized that its happening in all my files even in different projects. I'm new to flutter so I don't know if I need to completely refresh my system or if there is a specific part I need to redownload/ refresh. Any help would be greatly appreciated. Thank you.
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.
);
}
}
These are the errors I got...
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
I was able to solve the issue with:
flutter upgrade # download the new SDK for current channel
You may have to use the --force
flag to force the current SDK to upgrade to the new one.