mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 09:06:43 +08:00
Add a simple journal list
This commit is contained in:
158
lib/main.dart
158
lib/main.dart
@ -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),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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:
|
||||||
@ -55,5 +53,5 @@ flutter:
|
|||||||
# - asset: fonts/TrajanPro_Bold.ttf
|
# - asset: fonts/TrajanPro_Bold.ttf
|
||||||
# weight: 700
|
# weight: 700
|
||||||
#
|
#
|
||||||
# For details regarding fonts from package dependencies,
|
# For details regarding fonts from package dependencies,
|
||||||
# see https://flutter.io/custom-fonts/#from-packages
|
# see https://flutter.io/custom-fonts/#from-packages
|
||||||
|
Reference in New Issue
Block a user