Last active
March 31, 2022 10:13
-
-
Save rido-ramadan/80d194c967df8ad415a398187f47f495 to your computer and use it in GitHub Desktop.
Simple List Builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| class SimpleList extends StatelessWidget { | |
| const SimpleList({Key? key}) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: const Text('Simple List'), | |
| ), | |
| body: SafeArea( | |
| child: buildList(context), | |
| ), | |
| ); | |
| } | |
| Widget buildList(BuildContext context) { | |
| return ListView.separated( | |
| itemCount: nouns.length, | |
| itemBuilder: (context, index) { | |
| final name = nouns[index]; | |
| return ListTile( | |
| leading: const Icon(Icons.person), | |
| title: Text(name), | |
| trailing: const Icon(Icons.chevron_right), | |
| onTap: () => _showSnackBar(context, name), | |
| ); | |
| }, | |
| separatorBuilder: (context, index) => const Divider(), | |
| ); | |
| } | |
| void _showSnackBar(BuildContext context, String text) { | |
| ScaffoldMessenger.of(context).showSnackBar( | |
| SnackBar(content: Text(text)), | |
| ); | |
| } | |
| } | |
| void main() { | |
| runApp(const MaterialApp(title: 'Simple List App', home: SimpleList())); | |
| } | |
| const nouns = [ | |
| 'time', 'year', 'people', 'way', 'day', 'man', 'thing', 'woman', 'life', | |
| 'child', 'world', 'school', 'state', 'family', 'student', 'group', 'country', | |
| 'problem', 'hand', 'part', 'place', 'case', 'week', 'company', 'system', | |
| 'program', 'question', 'work', 'government', 'number', 'night', 'point', 'home', | |
| 'water', 'room', 'mother', 'area', 'money', 'story', 'fact', 'month', 'lot', | |
| 'right', 'study', 'book', | |
| ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment