hello world
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
title: 'HelloWorld',
home: Scaffold(
appBar: AppBar(
title: const Text('HelloWorld'),
),
),
),
);
}
This is pretty much the simplest meaningful flutter app. It displays a bar at
the top of that app reading "HelloWorld". Often you want to split the app into
two different subclasses of widget: a root-level FancyNameApp
widget that
never changes and a child MainScreen
widget that rebuilds when messages are
sent and internal state changes.
import 'package:flutter/material.dart';
void main() {
runApp(
const HelloApp(),
);
}
class HelloApp extends StatelessWidget {
const HelloApp({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: 'HelloWorld',
home: HelloScreen(),
);
}
}
class HelloScreen extends StatelessWidget {
const HelloScreen({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('HelloWorld'),
),
);
}
}
Typically, in this example you would need to make HelloScreen stateful and create a state for it.