text
stringlengths 1
372
|
---|
a constraint becomes tight when its constraint’s minimum size value
|
equals its maximum size value.
|
in SwiftUI, views might expand to the available space or
|
limit their size to that of its content.
|
flutter widgets behave in similar manner.
|
however, in flutter parent widgets can offer unbounded constraints.
|
unbounded constraints set their maximum values to infinity.
|
if the child expands and it has unbounded constraints,
|
flutter returns an overflow warning:
|
to learn how constraints work in flutter,
|
see understanding constraints.
|
<topic_end>
|
<topic_start>
|
design system
|
because flutter targets multiple platforms, your app doesn’t need
|
to conform to any design system.
|
though this guide features material widgets,
|
your flutter app can use many different design systems:
|
if you’re looking for a great reference app that features a
|
custom design system, check out wonderous.
|
<topic_end>
|
<topic_start>
|
UI basics
|
this section covers the basics of UI development in
|
flutter and how it compares to SwiftUI.
|
this includes how to start developing your app, display static text,
|
create buttons, react to on-press events, display lists, grids, and more.
|
<topic_end>
|
<topic_start>
|
getting started
|
in SwiftUI, you use app to start your app.
|
another common SwiftUI practice places the app body within a struct
|
that conforms to the view protocol as follows:
|
to start your flutter app, pass in an instance of your app to
|
the runApp function.
|
<code_start>
|
void main() {
|
runApp(const MyApp());
|
}
|
<code_end>
|
app is a widget. the build method describes the part of the
|
user interface it represents.
|
it’s common to begin your app with a WidgetApp class,
|
like CupertinoApp.
|
<code_start>
|
class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
widget build(BuildContext context) {
|
// returns a CupertinoApp that, by default,
|
// has the look and feel of an iOS app.
|
return const CupertinoApp(
|
home: HomePage(),
|
);
|
}
|
}
|
<code_end>
|
the widget used in HomePage might begin with the scaffold class.
|
scaffold implements a basic layout structure for an app.
|
<code_start>
|
class HomePage extends StatelessWidget {
|
const HomePage({super.key});
|
@override
|
widget build(BuildContext context) {
|
return const scaffold(
|
body: center(
|
child: text(
|
'hello, world!',
|
),
|
),
|
);
|
}
|
}
|
<code_end>
|
note how flutter uses the center widget.
|
SwiftUI renders a view’s contents in its center by default.
|
that’s not always the case with flutter.
|
scaffold doesn’t render its body widget at the center of the screen.
|
to center the text, wrap it in a center widget.
|
to learn about different widgets and their default behaviors, check out
|
the widget catalog.
|
<topic_end>
|
<topic_start>
|
adding buttons
|
in SwiftUI, you use the button struct to create a button.
|
to achieve the same result in flutter,
|
use the CupertinoButton class:
|
<code_start>
|
CupertinoButton(
|
onPressed: () {
|
// this closure is called when your button is tapped.
|
},
|
child: const Text('Do something'),
|
)
|
<code_end>
|
flutter gives you access to a variety of buttons with predefined styles.
|
the CupertinoButton class comes from the cupertino library.
|
widgets in the cupertino library use apple’s design system.
|
<topic_end>
|
<topic_start>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.