diff --git a/README.md b/README.md index 63f1d06..2b68c84 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# flutter-course \ No newline at end of file +# Flutter + +The directory was created using the Flutter framework and the Dart programming language. diff --git a/lib/main.dart b/lib/main.dart index 19dace7..775af0a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,31 +1,44 @@ -import 'package:english_words/english_words.dart'; 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: 'Startup Name Generator', - theme: ThemeData( - primaryColor: Colors.white, - ), home: RandomWords(), ); } } +class RandomWords extends StatefulWidget { + @override + _RandomWordsState createState() => _RandomWordsState(); +} + class _RandomWordsState extends State { final _suggestions = []; - final _saved = {}; - final _biggerFont = const TextStyle(fontSize: 18.0); + final _biggerFont = const TextStyle(fontSize: 18); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Startup Name Generator'), + ), + body: _buildSuggestions(), + ); + } + Widget _buildSuggestions() { return ListView.builder( padding: const EdgeInsets.all(16.0), itemBuilder: (context, i) { if (i.isOdd) return const Divider(); - final index = i ~/ 2; if (index >= _suggestions.length) { _suggestions.addAll(generateWordPairs().take(10)); @@ -35,80 +48,35 @@ class _RandomWordsState extends State { } Widget _buildRow(WordPair pair) { - final alreadySaved = _saved.contains(pair); return ListTile( title: Text( pair.asPascalCase, style: _biggerFont, ), - trailing: Icon( - alreadySaved ? Icons.favorite : Icons.favorite_border, - color: alreadySaved ? Colors.red : null, - semanticLabel: alreadySaved ? 'Remove from saved' : 'Save', - ), + trailing: const Text('Marked in the list!'), onTap: () { - setState(() { - if (alreadySaved) { - _saved.remove(pair); - } else { - _saved.add(pair); - } - }); + _showInformation(context); }, ); } +} - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text('Startup Name Generator'), - actions: [ - IconButton( - icon: const Icon(Icons.list), - onPressed: _pushSaved, - tooltip: 'Saved Suggestions', +void _showInformation(BuildContext context) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text("Notification!"), + content: const Text("Added to catalog"), + actions: [ + FlatButton( + child: const Text("Okay"), + onPressed: () { + Navigator.of(context).pop(); + }, ), ], - ), - body: _buildSuggestions(), - ); - } - - void _pushSaved() { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) { - final tiles = _saved.map( - (pair) { - return ListTile( - title: Text( - pair.asPascalCase, - style: _biggerFont, - ), - ); - }, - ); - final divided = tiles.isNotEmpty - ? ListTile.divideTiles( - context: context, - tiles: tiles, - ).toList() - : []; - - return Scaffold( - appBar: AppBar( - title: const Text('Saved Suggestions'), - ), - body: ListView(children: divided), - ); - }, - ), - ); - } + ); + }, + ); } - -class RandomWords extends StatefulWidget { - @override - State createState() => _RandomWordsState(); -} \ No newline at end of file