add icons
This commit is contained in:
parent
41b0a9893d
commit
9d569531b6
7
Makefile
7
Makefile
|
@ -1,3 +1,7 @@
|
|||
run:
|
||||
echo "flutter run"
|
||||
|
||||
|
||||
prep:
|
||||
flutter create flutter_test1
|
||||
flutter bin
|
||||
|
@ -5,3 +9,6 @@ prep:
|
|||
words:
|
||||
flutter pub add english_words
|
||||
flutter pub get
|
||||
|
||||
startupNamer:
|
||||
flutter create startup_namer
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// 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';
|
||||
|
||||
|
@ -8,16 +9,18 @@ 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: 'Welcome to Flutter',
|
||||
title: 'Startup Name Generator',
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Welcome to Flutter vJWC'),
|
||||
title: const Text('Startup Name Generator'),
|
||||
),
|
||||
body: const Center(
|
||||
child: RandomWords(),
|
||||
|
@ -25,20 +28,21 @@ class MyApp extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
// #enddocregion build
|
||||
}
|
||||
// #enddocregion MyApp
|
||||
|
||||
class RandomWords extends StatefulWidget {
|
||||
const RandomWords({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<RandomWords> createState() => _RandomWordsState();
|
||||
}
|
||||
|
||||
// #docregion RWS-var
|
||||
class _RandomWordsState extends State<RandomWords> {
|
||||
final _suggestions = <WordPair>[];
|
||||
final _saved = <WordPair>{}; // NEW
|
||||
final _biggerFont = const TextStyle(fontSize: 24);
|
||||
// #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) {
|
||||
|
@ -48,12 +52,32 @@ class _RandomWordsState extends State<RandomWords> {
|
|||
if (index >= _suggestions.length) {
|
||||
_suggestions.addAll(generateWordPairs().take(10)); /*4*/
|
||||
}
|
||||
return Text(
|
||||
final alreadySaved = _saved.contains(_suggestions[index]); // NEW
|
||||
// #docregion listTile
|
||||
return ListTile(
|
||||
title: Text(
|
||||
_suggestions[index].asPascalCase,
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)
|
||||
style: _biggerFont,
|
||||
),
|
||||
trailing: Icon( // NEW from here ...
|
||||
alreadySaved ? Icons.favorite : Icons.favorite_border,
|
||||
color: alreadySaved ? Colors.red : null,
|
||||
semanticLabel: alreadySaved ? 'Remove from saved' : 'Save',
|
||||
),
|
||||
);
|
||||
// #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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue