Skip to content

Commit 9dcf2a4

Browse files
committed
V1.1
1 parent a8c60a7 commit 9dcf2a4

File tree

10 files changed

+192
-107
lines changed

10 files changed

+192
-107
lines changed

lib/common/data.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ late final SharedPreferences prefs;
1212
const bool inProduction = const bool.fromEnvironment("dart.vm.product");// 判断是否处于生产模式
1313

1414
/// 初始化
15-
Future<void> init(){
15+
Future<void> init() {
1616
return Future(() async {
1717
prefs = await SharedPreferences.getInstance();
1818

@@ -54,33 +54,42 @@ void addASentence(String content) {
5454
}
5555

5656
/// 添加一篇日记
57-
void addADiary(String title, String content)
58-
{
57+
void addADiary(String title, String content) {
5958
db.insert("diary", {"title": title, "content": content});
6059
}
6160

62-
// 获取所有句子
61+
/// 获取所有句子
6362
Future<List<Map<String, dynamic>>> getSentences()
6463
async {
6564
return await db.query("sentence");
6665
}
6766

68-
// 获取所有日记
67+
/// 获取所有日记
6968
Future<List<Map<String, dynamic>>> getDiaries()
7069
async {
7170
return await db.query("diary");
7271
}
7372

7473
/// 删除一篇日记
75-
void deleteADiary(int id){
74+
void deleteADiary(int id) {
7675
db.delete("diary", where: "id = $id");
7776
}
7877

7978
/// 删除一句话
80-
void deleteASentence(int id){
79+
void deleteASentence(int id) {
8180
db.delete("sentence", where: "id = $id");
8281
}
8382

83+
/// 修改一句话
84+
void updateASentence(int id, String content) {
85+
db.update("sentence", {"content": content}, where: "id = $id");
86+
}
87+
88+
/// 修改一篇日记
89+
void updateADiary(int id, String title, String content) {
90+
db.update("diary", {"title": title, "content": content}, where: "id = $id");
91+
}
92+
8493
/// 关闭数据库
8594
void close() async {
8695
await db.close();

lib/dialogs/record_a_sentence.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,19 @@ import '../common/data.dart' as data;
44

55
/// 说一句话的对话框
66
class RecordASentenceDialog extends Dialog {
7+
int? id;
8+
String text;
9+
710
RecordASentenceDialog({
811
Key? key,
12+
this.id,
13+
this.text = "",
914
}) : super(key: key);
1015

1116
@override
1217
Widget build(BuildContext context) {
18+
TextEditingController controller = new TextEditingController(text: text);
19+
1320
return new Padding(
1421
padding: const EdgeInsets.all(12.0),
1522
child: new Material(
@@ -40,12 +47,18 @@ class RecordASentenceDialog extends Dialog {
4047
padding: const EdgeInsets.fromLTRB(10.0, 0, 10.0, 28.0),
4148
child: Center(
4249
child: new TextField(
50+
controller: controller,
4351
decoration: InputDecoration(hintText: "你想记的话"),
4452

4553
// 提交内容
4654
onSubmitted: (text) {
4755
Navigator.pop(context);
48-
data.addASentence(text);
56+
57+
if (this.id == null)
58+
data.addASentence(text);// 添加句子
59+
else
60+
data.updateASentence(this.id as int, text);// 修改句子
61+
4962
Fluttertoast.showToast(
5063
msg: "记录成功",
5164
backgroundColor: Colors.black45,

lib/main.dart

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import 'pages/help.dart';
55
import 'pages/sentences.dart';
66
import 'pages/diaries.dart';
77
import 'common/data.dart' as data;
8-
9-
/// 主题色:
10-
/// Color(0xFFF2F2EA) // 淡黄
11-
/// Color(0xFFE75A48) // 红
12-
/// Color(0xFF86D3BF) // 绿
13-
/// Color(0xFFD9E0BF) // 黄
14-
/// Color(0xFFBEEED8) // 浅绿
8+
import 'package:flutter/services.dart';
159

1610
class AppWidget extends StatefulWidget {
1711
@override
@@ -60,11 +54,11 @@ class _MurmurerState extends State<Murmurer> {
6054

6155
appBar: AppBar(
6256
title: const Text('Murmurer'),
63-
elevation: 0,// 取消阴影
6457
centerTitle: true,
6558
),
6659
// 侧栏
6760
drawer: Drawer(
61+
elevation: 0,
6862
child: ListView(
6963
padding: EdgeInsets.zero,
7064
children: <Widget>[
@@ -156,6 +150,7 @@ class MyApp extends MaterialApp {
156150
backgroundColor: Colors.white,
157151
scaffoldBackgroundColor: Colors.white,
158152
dialogBackgroundColor: Colors.white,
153+
appBarTheme: AppBarTheme(elevation: 0),// 取消阴影
159154
),
160155
home: new AppWidget(),
161156
localizationsDelegates: [
@@ -169,6 +164,15 @@ class MyApp extends MaterialApp {
169164
);
170165
}
171166

172-
void main() {
173-
runApp(new MyApp());
174-
}
167+
void main() async {
168+
WidgetsFlutterBinding.ensureInitialized();
169+
await SystemChrome.setPreferredOrientations(
170+
[
171+
DeviceOrientation.portraitUp, // 竖屏 Portrait 模式
172+
// DeviceOrientation.portraitDown,
173+
// DeviceOrientation.landscapeLeft, // 横屏 Landscape 模式
174+
// DeviceOrientation.landscapeRight,
175+
],
176+
);
177+
runApp(MyApp());
178+
}

lib/pages/diaries.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class _DiariesPagePageState extends State<DiariesPage> {
5858

5959
// 获取日记
6060
_getDiaries() {
61-
return Future.delayed(Duration(seconds: 1),() async {
61+
return Future.delayed(Duration(seconds: 0),() async {
6262
_diaries = await data.getDiaries();
6363
});
6464
}

lib/pages/diary.dart

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/material.dart';
3+
import '../pages/write_a_diary.dart';
34
import '../common/data.dart' as data;
5+
import '../common/widgets.dart';
46

57
/// 浏览日记
68
class DiaryPage extends StatelessWidget {
@@ -14,14 +16,13 @@ class DiaryPage extends StatelessWidget {
1416
return new Scaffold(
1517
appBar: AppBar(
1618
title: const Text('日记浏览'),
17-
elevation: 0,
1819
actions: <Widget>[
1920
// 删除按钮
2021
IconButton(
2122
icon: Icon(Icons.delete),
2223
onPressed: () {
2324
_delete(context);
24-
}),
25+
}),
2526
],
2627
),
2728

@@ -49,10 +50,41 @@ class DiaryPage extends StatelessWidget {
4950
SizedBox(height: 10),// 保留间距
5051

5152
// 内容
52-
Expanded(child: Text(
53-
_data["content"],
54-
style: TextStyle(fontSize: 18,),
55-
),),
53+
Expanded(child: SingleChildScrollView(
54+
child: Text(
55+
_data["content"],
56+
style: TextStyle(fontSize: 18,),
57+
),
58+
)),
59+
60+
SizedBox(height: 10),// 保留间距
61+
62+
// 编辑按钮
63+
Padding(
64+
padding: EdgeInsets.fromLTRB(100, 5, 100, 0),
65+
child: GradientButton(
66+
colors: [Color(0xFFFF7E5F), Color(0xFFFFAD77)],
67+
splashColor: Color(0xFFFF7E5F),
68+
onPressed: () {
69+
Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
70+
return new WriteADiaryPage(
71+
id: _data["id"],
72+
content: _data["content"],
73+
title: _data["title"],
74+
);
75+
})).then((value) => Navigator.pop(context, "refresh"));
76+
},
77+
child: Row(
78+
mainAxisSize: MainAxisSize.min,
79+
children: [
80+
Icon(Icons.edit, color: Colors.white,),
81+
SizedBox(width: 10),// 保留间距
82+
Text("编辑")
83+
],
84+
),
85+
borderRadius: BorderRadius.circular(100),
86+
),
87+
)
5688
],
5789
)
5890
)

lib/pages/help.dart

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,64 @@ class _HelpPageState extends State<HelpPage> {
2828
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
2929
switch (snapshot.connectionState) {
3030
case ConnectionState.done: // 执行完成
31-
return new Column(
32-
children: [
33-
new RichText(
34-
text: TextSpan(
35-
children: [
36-
TextSpan(
37-
text: '介绍\n',
38-
style: Theme.of(context).primaryTextTheme.headline6,
39-
),
40-
TextSpan(
41-
text: '《Murmurer》是一款用来记录生活的软件。\n\n',
42-
style: TextStyle(color: Colors.black),
43-
),
44-
TextSpan(
45-
text: '关于\n',
46-
style: Theme.of(context).primaryTextTheme.headline6,
47-
),
48-
TextSpan(
49-
text: '作者:',
50-
style: TextStyle(color: Colors.black),
51-
),
52-
TextSpan(
53-
text: '珒陶(陈锦涛)\n',
54-
style: TextStyle(color: Colors.blue),
55-
recognizer: TapGestureRecognizer()
56-
..onTap = () {
57-
launch('http://www.chenjt.com/');
58-
},
59-
),
60-
TextSpan(
61-
text: '版本:${_packageInfo.version}\n',
62-
style: TextStyle(color: Colors.black),
63-
),
64-
TextSpan(
65-
text: '数据库文件路径:${data.dbFilePath}\n',
66-
style: TextStyle(color: Colors.black),
67-
),
68-
],
69-
)
70-
),
31+
return Padding(
32+
padding: EdgeInsets.all(20),
33+
child: Column(
34+
children: [
35+
new Image(
36+
image: AssetImage("assets/images/icon.png"),
37+
height: 150,
38+
),
39+
new RichText(
40+
text: TextSpan(
41+
children: [
42+
TextSpan(
43+
text: '介绍\n',
44+
style: Theme.of(context).primaryTextTheme.headline6,
45+
),
46+
TextSpan(
47+
text: '《Murmurer》是一款用来记录生活的软件。\n\n',
48+
style: TextStyle(color: Colors.black),
49+
),
50+
TextSpan(
51+
text: '关于\n',
52+
style: Theme.of(context).primaryTextTheme.headline6,
53+
),
54+
TextSpan(
55+
text: '作者:',
56+
style: TextStyle(color: Colors.black),
57+
),
58+
TextSpan(
59+
text: '珒陶(陈锦涛)\n',
60+
style: TextStyle(color: Colors.blue),
61+
recognizer: TapGestureRecognizer()
62+
..onTap = () {
63+
launch('http://www.chenjt.com/');
64+
},
65+
),
66+
TextSpan(
67+
text: '版本:${_packageInfo.version}\n',
68+
style: TextStyle(color: Colors.black),
69+
),
70+
TextSpan(
71+
text: '数据库文件路径:${data.dbFilePath}\n',
72+
style: TextStyle(color: Colors.black),
73+
),
74+
],
75+
)
76+
),
7177

72-
Divider(),
73-
74-
ListTile(
75-
title: Text("许可"),//Text("Licenses"),
76-
trailing: Icon(Icons.keyboard_arrow_right),
77-
onTap: (){showLicensePage (
78-
context: context,
79-
);},
80-
),
81-
],
82-
);
78+
Divider(),
79+
//AboutListTile(),
80+
ListTile(
81+
title: Text("许可"),//Text("Licenses"),
82+
trailing: Icon(Icons.keyboard_arrow_right),
83+
onTap: (){showLicensePage (
84+
context: context,
85+
);},
86+
),
87+
],
88+
));
8389
default: // 未执行完成等情况
8490
return Container();
8591
}

lib/pages/home.dart

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,6 @@ class HomePage extends StatelessWidget {
3535
child: Text("写一篇日记", style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),),
3636
borderRadius: BorderRadius.circular(20.0),
3737
),
38-
/*ElevatedButton(
39-
child: Text("写一篇日记"),
40-
onPressed: () {
41-
writeADiary(context);
42-
},
43-
style: ElevatedButton.styleFrom(
44-
primary: Color(0xFFE75A48),
45-
minimumSize: Size(double.infinity, double.infinity),
46-
textStyle:
47-
TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
48-
shape: new RoundedRectangleBorder(
49-
borderRadius: new BorderRadius.circular(20.0),
50-
),
51-
),
52-
),*/
5338
),
5439
),
5540
],

0 commit comments

Comments
 (0)