Add a simple journal list

This commit is contained in:
Vishesh Handa
2018-05-15 16:17:09 +02:00
parent 27023eec84
commit 44b54bdc36
3 changed files with 59 additions and 112 deletions

View File

@ -1,110 +1,66 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
class JournalList extends StatefulWidget {
@override
createState() => new JournalListState();
}
class JournalListState extends State<JournalList> {
final _biggerFont = const TextStyle(fontSize: 18.0);
@override
Widget build(BuildContext context) {
var createButton = new FloatingActionButton(
onPressed: _newPost,
child: new Icon(Icons.add),
);
return new Scaffold(
appBar: new AppBar(
title: new Text('Journal'),
),
body: _buildSuggestions(),
floatingActionButton: createButton,
);
}
Widget _buildRow() {
var body = "The quick brown fox jumped over the very lazy dog, who then ran"
"all around the garden untill he fell down";
return new ListTile(
isThreeLine: true,
title: new Text(
"May 5, 2018",
style: _biggerFont,
),
subtitle: new Text("10:24" + "\n" + body),
onTap: () {
setState(() {});
},
);
}
Widget _buildSuggestions() {
return new ListView.builder(
padding: const EdgeInsets.all(8.0),
itemBuilder: (context, i) {
if (i.isOdd) return new Divider();
return _buildRow();
},
);
}
void _newPost() {
print("FOoOO");
}
}
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new MaterialApp( return new MaterialApp(title: 'Journal', home: new JournalList());
title: 'Startup Name Generator', home: new RandomWords());
}
}
class RandomWords extends StatefulWidget {
@override
createState() => new RandomWordsState();
}
class RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _saved = new Set<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) {
final alreadySaved = _saved.contains(pair);
return new ListTile(
title: new Text(
pair.asPascalCase,
style: _biggerFont,
),
trailing: new Icon(
alreadySaved ? Icons.favorite : Icons.favorite_border,
color: alreadySaved ? Colors.red : null,
),
onTap: () {
setState(() {
if (alreadySaved) {
_saved.remove(pair);
} else {
_saved.add(pair);
}
});
},
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Startup Name Generator'),
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.list),
onPressed: _pushSaved,
),
],
),
body: _buildSuggestions(),
);
}
void _pushSaved() {
Navigator.of(context).push(
new MaterialPageRoute(
builder: (context) {
final tiles = _saved.map(
(pair) {
return new ListTile(
title: new Text(
pair.asPascalCase,
style: _biggerFont,
),
);
},
);
final divided = ListTile
.divideTiles(
context: context,
tiles: tiles,
)
.toList();
return new Scaffold(
appBar: new AppBar(
title: new Text('Saved Suggestions'),
),
body: new ListView(children: divided),
);
},
),
);
} }
} }

View File

@ -85,13 +85,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.1.2" version: "0.1.2"
english_words:
dependency: "direct main"
description:
name: english_words
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter

View File

@ -1,5 +1,5 @@
name: journal name: journal
description: A new Flutter project. description: A simple journaling app.
dependencies: dependencies:
flutter: flutter:
@ -8,8 +8,6 @@ dependencies:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.0 cupertino_icons: ^0.1.0
english_words: ^3.1.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: