当前链接
应该改为最新链接
startup_namer/step4_infinite_list/lib/main.dart @master
// 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());
}
// #docregion MyApp
class MyApp extends StatelessWidget {
const MyApp({super.key});
// #docregion build
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Startup Name Generator',
home: Scaffold(
appBar: AppBar(
title: const Text('Startup Name Generator'),
),
body: const Center(
child: RandomWords(),
),
),
);
}
// #enddocregion build
}
// #enddocregion MyApp
// #docregion RWS-var
class _RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _biggerFont = const TextStyle(fontSize: 18);
// #enddocregion RWS-var
// #docregion RWS-build
@override
Widget build(BuildContext context) {
// #docregion itemBuilder
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*/
}
// #docregion listTile
return ListTile(
title: Text(
_suggestions[index].asPascalCase,
style: _biggerFont,
),
);
// #enddocregion listTile
},
);
// #enddocregion itemBuilder
}
// #enddocregion RWS-build
// #docregion RWS-var
}
// #enddocregion RWS-var
class RandomWords extends StatefulWidget {
const RandomWords({super.key});
@override
State<RandomWords> createState() => _RandomWordsState();
}