Skip to content

Commit

Permalink
add: ListView
Browse files Browse the repository at this point in the history
  • Loading branch information
LanceGin committed Sep 22, 2018
1 parent fbb374e commit db2d079
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
59 changes: 49 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,59 @@
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';

void main() => runApp(new MyApp());
void main() => runApp(new MinaOTP());

class MyApp extends StatelessWidget {
class MinaOTP extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Welcome to Flutter',
home: new Scaffold(
appBar: new AppBar(
title: new Text('Welcome to Flutter'),
),
body: new Center(
child: new Text('Hello World'),
),
title: 'MinaOTP',
home: new RandomWords(),
);
}
}

class RandomWords extends StatefulWidget {
@override
createState() => new RandomWordsState();
}

class RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _biggerFont = const TextStyle(fontSize: 18.0);

Widget _buildSuggestions() {
return new ListView.builder(
padding: const EdgeInsets.all(16.0),
itemBuilder: (context, i) {
if (i.isOdd) return new Divider();

final index = i ~/ 2;
if (index >= _suggestions.length) {
_suggestions.addAll(generateWordPairs().take(10));
}

return _buildRow(_suggestions[index]);
}
);
}

Widget _buildRow(WordPair pair) {
return new ListTile(
title: new Text(
pair.asPascalCase,
style: _biggerFont,
),
);
}

@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('MinaOTP'),
),
body: _buildSuggestions(),
);
}
}
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.1.2"
english_words:
dependency: "direct main"
description:
name: english_words
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.1.3"
flutter:
dependency: "direct main"
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
english_words: ^3.1.0

dev_dependencies:
flutter_test:
Expand Down
2 changes: 1 addition & 1 deletion test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:minaotp_flutter/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp());
await tester.pumpWidget(new MinaOTP());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down

0 comments on commit db2d079

Please sign in to comment.