60 lines
1.5 KiB
Dart
60 lines
1.5 KiB
Dart
// Copyright 2018 The Flutter team. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
import 'package:english_words/english_words.dart';
|
|
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(
|
|
title: 'Welcome to Flutter',
|
|
home: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Welcome to Flutter vJWC'),
|
|
),
|
|
body: const Center(
|
|
child: RandomWords(),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class RandomWords extends StatefulWidget {
|
|
const RandomWords({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<RandomWords> createState() => _RandomWordsState();
|
|
}
|
|
|
|
class _RandomWordsState extends State<RandomWords> {
|
|
final _suggestions = <WordPair>[];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(16.0),
|
|
itemBuilder: /*1*/ (context, i) {
|
|
if (i.isOdd) return const Divider(); /*2*/
|
|
|
|
final index = i ~/ 2; /*3*/
|
|
if (index >= _suggestions.length) {
|
|
_suggestions.addAll(generateWordPairs().take(10)); /*4*/
|
|
}
|
|
return Text(
|
|
_suggestions[index].asPascalCase,
|
|
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
}
|