通过 flutter 实现一个列表功能
使用 english_words 包实现生成列表的功能:
import ‘package:english_words/english_words.dart‘; import ‘package:flutter/material.dart‘; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: RandomWords(), ); } } class RandomWordsState extends State<RandomWords> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(‘Startup Name Generator‘), ), body: _buildSuggestions(), ); } final _suggestions = <WordPair>[]; final _biggerFont = const TextStyle(fontSize: 18.0); Widget _buildSuggestions() { return ListView.builder( padding: const EdgeInsets.all(16.0), itemBuilder: (context, i) { if (i.isOdd) return Divider(); final index = i ~/ 2; if (index >= _suggestions.length) { _suggestions.addAll(generateWordPairs().take(10)); } return _buildRow(_suggestions[index]); } ); } Widget _buildRow(WordPair pair) { return ListTile( title: Text( pair.asPascalCase, style: _biggerFont, ), ); } } class RandomWords extends StatefulWidget { @override RandomWordsState createState() => RandomWordsState(); }
相关推荐
yanyongtao 2020-11-02
dangai00 2020-07-18
MrFuWen 2020-06-28
boredbird 2020-06-26
fengling 2020-06-16
MIKUScallion 2020-06-11
80447704 2020-06-09
XuDanT 2020-06-07
MrFuWen 2020-06-06
aNian 2020-06-03
dongxurr 2020-06-01
冒烟儿 2020-06-01
Roka 2020-05-25
zhangdy0 2020-05-25
ErixHao 2020-05-20
ErixHao 2020-05-16