Compare commits

..

No commits in common. "4a842d1698a39cec226233aab885d2f68335e847" and "41b0a9893d2a04847372abc230f87052f2f7b45e" have entirely different histories.

2 changed files with 12 additions and 51 deletions

View File

@ -1,7 +1,3 @@
run:
echo "flutter run"
prep:
flutter create flutter_test1
flutter bin
@ -9,6 +5,3 @@ prep:
words:
flutter pub add english_words
flutter pub get
startupNamer:
flutter create startup_namer

View File

@ -1,7 +1,6 @@
// 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';
@ -9,18 +8,16 @@ 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',
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Startup Name Generator'),
title: const Text('Welcome to Flutter vJWC'),
),
body: const Center(
child: RandomWords(),
@ -28,21 +25,20 @@ class MyApp extends StatelessWidget {
),
);
}
// #enddocregion build
}
// #enddocregion MyApp
// #docregion RWS-var
class RandomWords extends StatefulWidget {
const RandomWords({Key? key}) : super(key: key);
@override
State<RandomWords> createState() => _RandomWordsState();
}
class _RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _saved = <WordPair>{}; // NEW
final _biggerFont = const TextStyle(fontSize: 36);
// #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) {
@ -52,40 +48,12 @@ class _RandomWordsState extends State<RandomWords> {
if (index >= _suggestions.length) {
_suggestions.addAll(generateWordPairs().take(10)); /*4*/
}
final alreadySaved = _saved.contains(_suggestions[index]); // NEW
// #docregion listTile
return ListTile(
title: Text(
return Text(
_suggestions[index].asPascalCase,
style: _biggerFont,
),
trailing: Icon( // NEW from here ...
alreadySaved ? Icons.favorite : Icons.favorite_border,
color: alreadySaved ? Colors.red : null,
semanticLabel: alreadySaved ? 'Remove from saved' : 'Save',
),
onTap: () { // NEW from here ...
setState(() {
if (alreadySaved) {
_saved.remove(_suggestions[index]);
} else {
_saved.add(_suggestions[index]);
}
});
});
// #enddocregion listTile
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)
);
},
);
// #enddocregion itemBuilder
}
// #enddocregion RWS-build
// #docregion RWS-var
}
// #enddocregion RWS-var
class RandomWords extends StatefulWidget {
const RandomWords({super.key});
@override
State<RandomWords> createState() => _RandomWordsState();
}