text stringlengths 1 474 |
|---|
), |
);<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', |
theme: ThemeData( |
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), |
textSelectionTheme: |
const TextSelectionThemeData(selectionColor: Colors.red)), |
home: const SampleAppPage(), |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
How do I add style themes? |
In React Native, common themes are defined for |
components in stylesheets and then used in components.In Flutter, create uniform styling for almost everything |
by defining the styling in the ThemeData |
class and passing it to the theme property in the |
MaterialApp widget. |
<code_start>@override |
Widget build(BuildContext context) { |
return MaterialApp( |
theme: ThemeData( |
primaryColor: Colors.cyan, |
brightness: Brightness.dark, |
), |
home: const StylingPage(), |
); |
}<code_end> |
A Theme can be applied even without using the MaterialApp widget. |
The Theme widget takes a ThemeData in its data parameter |
and applies the ThemeData to all of its children widgets. |
<code_start>@override |
Widget build(BuildContext context) { |
return Theme( |
data: ThemeData( |
primaryColor: Colors.cyan, |
brightness: brightness, |
), |
child: Scaffold( |
backgroundColor: Theme.of(context).primaryColor, |
//... |
), |
); |
}<code_end> |
<topic_end> |
<topic_start> |
State management |
State is information that can be read synchronously |
when a widget is built or information |
that might change during the lifetime of a widget. |
To manage app state in Flutter, |
use a StatefulWidget paired with a State object.For more information on ways to approach managing state in Flutter, |
see State management.<topic_end> |
<topic_start> |
The StatelessWidget |
A StatelessWidget in Flutter is a widget |
that doesn’t require a state change— |
it has no internal state to manage.Stateless widgets are useful when the part of the user interface |
you are describing does not depend on anything other than the |
configuration information in the object itself and the |
BuildContext in which the widget is inflated.AboutDialog, CircleAvatar, and Text are examples |
of stateless widgets that subclass StatelessWidget. |
<code_start>import 'package:flutter/material.dart'; |
void main() => runApp( |
const MyStatelessWidget( |
text: 'StatelessWidget Example to show immutable data', |
), |
); |
class MyStatelessWidget extends StatelessWidget { |
const MyStatelessWidget({ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.