text
stringlengths
1
372
flutter uses the stack
widget to arrange children widgets in layers.
the widgets can entirely or partially overlap the base widget.
the stack widget positions its children relative to the edges of its box.
this class is useful if you simply want to overlap several children widgets.
<code_start>
@override
widget build(BuildContext context) {
return stack(
alignment: const alignment(0.6, 0.6),
children: <widget>[
const CircleAvatar(
backgroundImage: NetworkImage(
'https://avatars3.githubusercontent.com/u/14101776?v=4',
),
),
container(
color: colors.black45,
child: const Text('Flutter'),
),
],
);
<code_end>
the previous example uses stack to overlay a container
(that displays its text on a translucent black background)
on top of a CircleAvatar.
the stack offsets the text using the alignment property
and alignment coordinates.
for more information, see the stack class documentation.
<topic_end>
<topic_start>
styling
<topic_end>
<topic_start>
how do i style my components?
in react native, inline styling and stylesheets.create
are used to style components.
in flutter, a text widget can take a TextStyle class
for its style property. if you want to use the same text
style in multiple places, you can create a
TextStyle class and use it for multiple text widgets.
<code_start>
const TextStyle textStyle = TextStyle(
color: colors.cyan,
fontSize: 32,
fontWeight: FontWeight.w600,
);
return const center(
child: column(
children: <widget>[
Text('Sample text', style: textStyle),
padding(
padding: EdgeInsets.all(20),
child: icon(
icons.lightbulb_outline,
size: 48,
color: Colors.redAccent,
),
),
],
),
);
<code_end>
<topic_end>
<topic_start>
how do i use icons and colors?
react native doesn’t include support for icons
so third party libraries are used.
in flutter, importing the material library also pulls in the
rich set of material icons and colors.
<code_start>
return const Icon(Icons.lightbulb_outline, color: Colors.redAccent);
<code_end>
when using the icons class,
make sure to set uses-material-design: true in
the project’s pubspec.yaml file.
this ensures that the MaterialIcons font,
which displays the icons, is included in your app.
in general, if you intend to use the material library,
you should include this line.
flutter’s cupertino (ios-style) package provides high
fidelity widgets for the current iOS design language.
to use the CupertinoIcons font,
add a dependency for cupertino_icons in your project’s
pubspec.yaml file.
to globally customize the colors and styles of components,
use ThemeData to specify default colors
for various aspects of the theme.
set the theme property in MaterialApp to the ThemeData object.
the colors class provides colors
from the material design color palette.
the following example sets the color scheme from seed to deepPurple
and the text selection to red.
<code_start>
class SampleApp extends StatelessWidget {
const SampleApp({super.key});
@override
widget build(BuildContext context) {
return MaterialApp(
title: 'sample app',