Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Created September 26, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/9c6de6827c57395320fce2a03c7e936d to your computer and use it in GitHub Desktop.
Save DaisukeNagata/9c6de6827c57395320fce2a03c7e936d to your computer and use it in GitHub Desktop.
The column contains a list.
import 'package:flutter/material.dart';
void main() {
runApp(
const MyApp(),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(primarySwatch: Colors.blue),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
static var items = [
'Item 1',
'Item 2',
'Item 3',
'Item 4',
'Item 5',
'Item 6',
'Item 7',
'Item 8',
'Item 9',
'Item 10',
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
..._textList(),
],
),
);
}
List<Widget> _textList() {
return items.asMap().entries.map((entry) {
int idx = entry.key;
String item = entry.value;
return Center(
child: Text(
item,
style: TextStyle(
color: idx == 0 ? Colors.black : Colors.grey,
),
),
);
}).toList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment