Skip to content

Instantly share code, notes, and snippets.

@snova301
Created June 2, 2019 07:33
Show Gist options
  • Save snova301/4db4fc20f5873523b2ab8ebe31b5bc9d to your computer and use it in GitHub Desktop.
Save snova301/4db4fc20f5873523b2ab8ebe31b5bc9d to your computer and use it in GitHub Desktop.
flutter get started, part1 step4
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// title: 'Welcome to Flutter', // 削除
// home: Scaffold( // 削除
title: 'Startup Name Generator', // 追加
home: RandomWords(), // 追加
// appBar: AppBar( // 削除
// title: Text('Welcome to Flutter'), // 削除
// ),
// body: Center( // 削除
// // child: Text (wordPair.asPascalCase), // 削除
// child: RandomWords(), // 削除
// ),
// ),
);
}
}
class RandomWords extends StatefulWidget {
@override
RandomWordsState createState() => RandomWordsState();
}
class RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _biggerFont = const TextStyle(fontSize: 18.0);
Widget _buildSuggestions() {
return ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: /*1*/ (context, i) {
if (i.isOdd) return Divider(); /*2*/
final index = i ~/ 2; /*3*/
if (index >= _suggestions.length) {
_suggestions.addAll(generateWordPairs().take(10)); /*4*/
}
return _buildRow(_suggestions[index]);
});
}
Widget _buildRow(WordPair pair) {
return ListTile(
title: Text(
pair.asPascalCase,
style: _biggerFont,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Startup Name Generator'),
),
body: _buildSuggestions(),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment