29
loading...
This website collects cookies to deliver better user experience
lib/main.dart
file until now.Note: this guide does not tell you the best practices about folder structures, just an introduction to how it works.
screens
and place a file called home.dart
inside this folder.import 'package:flutter/material.dart';
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
),
TextButton(
onPressed: _incrementCounter,
child: const Text('Add number'),
),
]),
),
);
}
}
main.dart
file, we can remove all that code, so it looks like this.import 'package:flutter/material.dart';
void main() async {
runApp(
MaterialApp(debugShowCheckedModeBanner: false, home: MyApp()),
);
}
import 'package:flutter_app/screens/home.dart';
package:flutter_app
thing about?flutter_app
refers to our application. If you are wondering where we set this variable, open up the pubspec.yaml
and check out the name
variable!name: flutter_app