text stringlengths 1 372 |
|---|
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()), |
); |
} |
} |
<code_end> |
<topic_end> |
<topic_start> |
layouts |
<topic_end> |
<topic_start> |
how do i use widgets to define layout properties? |
in react native, most of the layout can be done with the props |
that are passed to a specific component. |
for example, you could use the style prop on the view component |
in order to specify the flexbox properties. |
to arrange your components in a column, you would specify a prop such as: |
flexDirection: 'column'. |
in flutter, the layout is primarily defined by widgets |
specifically designed to provide layout, |
combined with control widgets and their style properties. |
for example, the column and row widgets |
take an array of children and align them |
vertically and horizontally respectively. |
a container widget takes a combination of |
layout and styling properties, and a |
center widget centers its child widgets. |
<code_start> |
@override |
widget build(BuildContext context) { |
return center( |
child: column( |
children: <widget>[ |
container( |
color: colors.red, |
width: 100, |
height: 100, |
), |
container( |
color: colors.blue, |
width: 100, |
height: 100, |
), |
container( |
color: colors.green, |
width: 100, |
height: 100, |
), |
], |
), |
); |
<code_end> |
flutter provides a variety of layout widgets in its core widget library. |
for example, padding, align, and stack. |
for a complete list, see layout widgets. |
<topic_end> |
<topic_start> |
how do i layer widgets? |
in react native, components can be layered using absolute positioning. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.