text
stringlengths 1
474
|
|---|
image,
|
fit: BoxFit.cover,
|
);<code_end>
|
Create an Icon widget:
|
<code_start>Icon(
|
Icons.star,
|
color: Colors.red[500],
|
),<code_end>
|
<topic_end>
|
<topic_start>
|
3. Add the visible widget to the layout widget
|
All layout widgets have either of the following:Add the Text widget to the Center widget:
|
<code_start>const Center(
|
child: Text('Hello World'),
|
),<code_end>
|
<topic_end>
|
<topic_start>
|
4. Add the layout widget to the page
|
A Flutter app is itself a widget, and most widgets have a build()
|
method. Instantiating and returning a widget in the app’s build() method
|
displays the widget.<topic_end>
|
<topic_start>Material apps
|
For a Material app, you can use a Scaffold widget;
|
it provides a default banner, background color,
|
and has API for adding drawers, snack bars, and bottom sheets.
|
Then you can add the Center widget directly to the body
|
property for the home page.
|
<code_start>class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
Widget build(BuildContext context) {
|
const String appTitle = 'Flutter layout demo';
|
return MaterialApp(
|
title: appTitle,
|
home: Scaffold(
|
appBar: AppBar(
|
title: const Text(appTitle),
|
),
|
body: const Center(
|
child: Text('Hello World'),
|
),
|
),
|
);
|
}
|
}<code_end>
|
info Note
|
The Material library implements widgets that follow Material
|
Design principles. When designing your UI, you can exclusively use
|
widgets from the standard widgets library, or you can use
|
widgets from the Material library. You can mix widgets from both
|
libraries, you can customize existing widgets,
|
or you can build your own set of custom widgets.<topic_end>
|
<topic_start>Cupertino apps
|
To create a Cupertino app, use CupertinoApp and CupertinoPageScaffold widgets.Unlike Material, it doesn’t provide a default banner or background color.
|
You need to set these yourself.To add an iOS-styled navigation bar to the top of your app, add a
|
CupertinoNavigationBar widget to the navigationBar
|
property of your scaffold.
|
You can use the colors that CupertinoColors provides to
|
configure your widgets to match iOS design.To learn what other UI components you can add, check out the
|
Cupertino library.
|
<code_start>class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
Widget build(BuildContext context) {
|
return const CupertinoApp(
|
title: 'Flutter layout demo',
|
theme: CupertinoThemeData(
|
brightness: Brightness.light,
|
primaryColor: CupertinoColors.systemBlue,
|
),
|
home: CupertinoPageScaffold(
|
navigationBar: CupertinoNavigationBar(
|
backgroundColor: CupertinoColors.systemGrey,
|
middle: Text('Flutter layout demo'),
|
),
|
child: Center(
|
child: Column(
|
mainAxisAlignment: MainAxisAlignment.center,
|
children: <Widget>[
|
Text('Hello World'),
|
],
|
),
|
),
|
),
|
);
|
}
|
}<code_end>
|
info Note
|
The Cupertino library implements widgets that follow
|
Apple’s Human Interface Guidelines for iOS.
|
When designing your UI, you can use
|
widgets from the standard widgets library, or the Cupertino library.
|
You can mix widgets from both libraries, you can customize existing widgets,
|
or you can build your own set of custom widgets.<topic_end>
|
<topic_start>Non-Material apps
|
For a non-Material app, you can add the Center widget to the app’s
|
build() method:
|
<code_start>class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.