Skip to content

Commit

Permalink
Use ListView.builder to create dynamic lists
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhidsharma08121988 committed Nov 23, 2023
1 parent ea47318 commit 3eb2e67
Showing 1 changed file with 17 additions and 24 deletions.
41 changes: 17 additions & 24 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

void main() => runApp(MyApp());
void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
// TODO: implement key
MyApp({super.key});
const MyApp({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -22,30 +22,23 @@ class MyApp extends StatelessWidget {
centerTitle: true,
title: const Text('Word Pair Generator'),
),
body: ListView(
padding: const EdgeInsets.all(1),
children: generateListOFWordPair,
)));
body: generateListOFWordPair));
}

List<Widget> get generateListOFWordPair {
return <Widget>[
Container(
height: 50,
color: Colors.amber[600],
child: Center(child: wordPairGenerator()),
),
Container(
height: 50,
color: Colors.amber[500],
child: Center(child: wordPairGenerator()),
),
Container(
height: 50,
color: Colors.amber[100],
child: Center(child: wordPairGenerator()),
),
];
Widget get generateListOFWordPair {
final List<String> entries = <String>['A', 'B', 'C'];
final List<int> colorCodes = <int>[600, 500, 100];

return ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: entries.length,
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
color: Colors.amber[colorCodes[index]],
child: Center(child: Text('Entry ${entries[index]}')),
);
});
}
}

Expand Down

0 comments on commit 3eb2e67

Please sign in to comment.