text
stringlengths 1
372
|
|---|
default drag for scrolling devices.
|
<code_start>
|
import 'package:flutter/material.dart';
|
void main() => runApp(const MyApp());
|
class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
widget build(BuildContext context) {
|
const title = 'horizontal list';
|
return MaterialApp(
|
title: title,
|
home: scaffold(
|
appBar: AppBar(
|
title: const text(title),
|
),
|
body: container(
|
margin: const EdgeInsets.symmetric(vertical: 20),
|
height: 200,
|
child: ListView(
|
// this next line does the trick.
|
scrollDirection: axis.horizontal,
|
children: <widget>[
|
container(
|
width: 160,
|
color: colors.red,
|
),
|
container(
|
width: 160,
|
color: colors.blue,
|
),
|
container(
|
width: 160,
|
color: colors.green,
|
),
|
container(
|
width: 160,
|
color: colors.yellow,
|
),
|
container(
|
width: 160,
|
color: colors.orange,
|
),
|
],
|
),
|
),
|
),
|
);
|
}
|
}
|
<code_end>
|
<topic_end>
|
<topic_start>
|
create a grid list
|
in some cases, you might want to display your items as a grid rather than
|
a normal list of items that come one after the next.
|
for this task, use the GridView widget.
|
the simplest way to get started using grids is by using the
|
GridView.count() constructor,
|
because it allows you to specify how many rows or columns you’d like.
|
to visualize how GridView works,
|
generate a list of 100 widgets that display their index in the list.
|
<code_start>
|
GridView.count(
|
// create a grid with 2 columns. if you change the scrollDirection to
|
// horizontal, this produces 2 rows.
|
crossAxisCount: 2,
|
// generate 100 widgets that display their index in the list.
|
children: list.generate(100, (index) {
|
return center(
|
child: text(
|
'item $index',
|
style: Theme.of(context).textTheme.headlineSmall,
|
),
|
);
|
}),
|
),
|
<code_end>
|
<topic_end>
|
<topic_start>
|
interactive example
|
<code_start>
|
import 'package:flutter/material.dart';
|
void main() {
|
runApp(const MyApp());
|
}
|
class MyApp extends StatelessWidget {
|
const MyApp({super.key});
|
@override
|
widget build(BuildContext context) {
|
const title = 'grid list';
|
return MaterialApp(
|
title: title,
|
home: scaffold(
|
appBar: AppBar(
|
title: const text(title),
|
),
|
body: GridView.count(
|
// create a grid with 2 columns. if you change the scrollDirection to
|
// horizontal, this produces 2 rows.
|
crossAxisCount: 2,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.