text
stringlengths 1
474
|
---|
size if needed.In Flutter, use the Image.network constructor to include
|
an image from a URL.
|
<code_start>Image.network('https://docs.flutter.dev/assets/images/docs/owl.jpg');<code_end>
|
<topic_end>
|
<topic_start>
|
How do I install packages and package plugins?
|
Flutter supports using shared packages contributed by other developers to the
|
Flutter and Dart ecosystems. This allows you to quickly build your app without
|
having to develop everything from scratch. Packages that contain
|
platform-specific code are known as package plugins.In React Native, you would use yarn add {package-name} or
|
npm install --save {package-name} to install packages
|
from the command line.In Flutter, install a package using the following instructions:
|
<code_start>import 'package:flutter/material.dart';<code_end>
|
For more information, see Using Packages and
|
Developing Packages & Plugins.You can find many packages shared by Flutter developers in the
|
Flutter packages section of pub.dev.<topic_end>
|
<topic_start>
|
Flutter widgets
|
In Flutter, you build your UI out of widgets that describe what their view
|
should look like given their current configuration and state.Widgets are often composed of many small,
|
single-purpose widgets that are nested to produce powerful effects.
|
For example, the Container widget consists of
|
several widgets responsible for layout, painting, positioning, and sizing.
|
Specifically, the Container widget includes the LimitedBox,
|
ConstrainedBox, Align, Padding, DecoratedBox, and Transform widgets.
|
Rather than subclassing Container to produce a customized effect, you can
|
compose these and other simple widgets in new and unique ways.The Center widget is another example of how you can control the layout.
|
To center a widget, wrap it in a Center widget and then use layout
|
widgets for alignment, row, columns, and grids.
|
These layout widgets do not have a visual representation of their own.
|
Instead, their sole purpose is to control some aspect of another
|
widget’s layout. To understand why a widget renders in a
|
certain way, it’s often helpful to inspect the neighboring widgets.For more information, see the Flutter Technical Overview.For more information about the core widgets from the Widgets package,
|
see Flutter Basic Widgets,
|
the Flutter Widget Catalog,
|
or the Flutter Widget Index.<topic_end>
|
<topic_start>
|
Views
|
<topic_end>
|
<topic_start>
|
What is the equivalent of the View container?
|
In React Native, View is a container that supports layout with Flexbox,
|
style, touch handling, and accessibility controls.In Flutter, you can use the core layout widgets in the Widgets
|
library, such as Container, Column,
|
Row, and Center.
|
For more information, see the Layout Widgets catalog.<topic_end>
|
<topic_start>
|
What is the equivalent of FlatList or SectionList?
|
A List is a scrollable list of components arranged vertically.In React Native, FlatList or SectionList are used to render simple or
|
sectioned lists.ListView is Flutter’s most commonly used scrolling widget.
|
The default constructor takes an explicit list of children.
|
ListView is most appropriate for a small number of widgets.
|
For a large or infinite list, use ListView.builder,
|
which builds its children on demand and only builds
|
those children that are visible.
|
<code_start>var data = [
|
'Hello',
|
'World',
|
];
|
return ListView.builder(
|
itemCount: data.length,
|
itemBuilder: (context, index) {
|
return Text(data[index]);
|
},
|
);<code_end>
|
To learn how to implement an infinite scrolling list, see the official
|
infinite_list sample.<topic_end>
|
<topic_start>
|
How do I use a Canvas to draw or paint?
|
In React Native, canvas components aren’t present
|
so third party libraries like react-native-canvas are used.In Flutter, you can use the CustomPaint
|
and CustomPainter classes to draw to the canvas.The following example shows how to draw during the paint phase using the
|
CustomPaint widget. It implements the abstract class, CustomPainter,
|
and passes it to CustomPaint’s painter property.
|
CustomPaint subclasses must implement the paint()
|
and shouldRepaint() methods.
|
<code_start>class MyCanvasPainter extends CustomPainter {
|
const MyCanvasPainter();
|
@override
|
void paint(Canvas canvas, Size size) {
|
final Paint paint = Paint()..color = Colors.amber;
|
canvas.drawCircle(const Offset(100, 200), 40, paint);
|
final Paint paintRect = Paint()..color = Colors.lightBlue;
|
final Rect rect = Rect.fromPoints(
|
const Offset(150, 300),
|
const Offset(300, 400),
|
);
|
canvas.drawRect(rect, paintRect);
|
}
|
@override
|
bool shouldRepaint(MyCanvasPainter oldDelegate) => false;
|
}
|
class MyCanvasWidget extends StatelessWidget {
|
const MyCanvasWidget({super.key});
|
@override
|
Widget build(BuildContext context) {
|
return const Scaffold(
|
body: CustomPaint(painter: MyCanvasPainter()),
|
);
|
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.