Skip to content

Commit

Permalink
V1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjt2001 committed Aug 24, 2021
1 parent a8c60a7 commit 9dcf2a4
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 107 deletions.
23 changes: 16 additions & 7 deletions lib/common/data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ late final SharedPreferences prefs;
const bool inProduction = const bool.fromEnvironment("dart.vm.product");// 判断是否处于生产模式

/// 初始化
Future<void> init(){
Future<void> init() {
return Future(() async {
prefs = await SharedPreferences.getInstance();

Expand Down Expand Up @@ -54,33 +54,42 @@ void addASentence(String content) {
}

/// 添加一篇日记
void addADiary(String title, String content)
{
void addADiary(String title, String content) {
db.insert("diary", {"title": title, "content": content});
}

// 获取所有句子
/// 获取所有句子
Future<List<Map<String, dynamic>>> getSentences()
async {
return await db.query("sentence");
}

// 获取所有日记
/// 获取所有日记
Future<List<Map<String, dynamic>>> getDiaries()
async {
return await db.query("diary");
}

/// 删除一篇日记
void deleteADiary(int id){
void deleteADiary(int id) {
db.delete("diary", where: "id = $id");
}

/// 删除一句话
void deleteASentence(int id){
void deleteASentence(int id) {
db.delete("sentence", where: "id = $id");
}

/// 修改一句话
void updateASentence(int id, String content) {
db.update("sentence", {"content": content}, where: "id = $id");
}

/// 修改一篇日记
void updateADiary(int id, String title, String content) {
db.update("diary", {"title": title, "content": content}, where: "id = $id");
}

/// 关闭数据库
void close() async {
await db.close();
Expand Down
15 changes: 14 additions & 1 deletion lib/dialogs/record_a_sentence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import '../common/data.dart' as data;

/// 说一句话的对话框
class RecordASentenceDialog extends Dialog {
int? id;
String text;

RecordASentenceDialog({
Key? key,
this.id,
this.text = "",
}) : super(key: key);

@override
Widget build(BuildContext context) {
TextEditingController controller = new TextEditingController(text: text);

return new Padding(
padding: const EdgeInsets.all(12.0),
child: new Material(
Expand Down Expand Up @@ -40,12 +47,18 @@ class RecordASentenceDialog extends Dialog {
padding: const EdgeInsets.fromLTRB(10.0, 0, 10.0, 28.0),
child: Center(
child: new TextField(
controller: controller,
decoration: InputDecoration(hintText: "你想记的话"),

// 提交内容
onSubmitted: (text) {
Navigator.pop(context);
data.addASentence(text);

if (this.id == null)
data.addASentence(text);// 添加句子
else
data.updateASentence(this.id as int, text);// 修改句子

Fluttertoast.showToast(
msg: "记录成功",
backgroundColor: Colors.black45,
Expand Down
26 changes: 15 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ import 'pages/help.dart';
import 'pages/sentences.dart';
import 'pages/diaries.dart';
import 'common/data.dart' as data;

/// 主题色:
/// Color(0xFFF2F2EA) // 淡黄
/// Color(0xFFE75A48) // 红
/// Color(0xFF86D3BF) // 绿
/// Color(0xFFD9E0BF) // 黄
/// Color(0xFFBEEED8) // 浅绿
import 'package:flutter/services.dart';

class AppWidget extends StatefulWidget {
@override
Expand Down Expand Up @@ -60,11 +54,11 @@ class _MurmurerState extends State<Murmurer> {

appBar: AppBar(
title: const Text('Murmurer'),
elevation: 0,// 取消阴影
centerTitle: true,
),
// 侧栏
drawer: Drawer(
elevation: 0,
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
Expand Down Expand Up @@ -156,6 +150,7 @@ class MyApp extends MaterialApp {
backgroundColor: Colors.white,
scaffoldBackgroundColor: Colors.white,
dialogBackgroundColor: Colors.white,
appBarTheme: AppBarTheme(elevation: 0),// 取消阴影
),
home: new AppWidget(),
localizationsDelegates: [
Expand All @@ -169,6 +164,15 @@ class MyApp extends MaterialApp {
);
}

void main() {
runApp(new MyApp());
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations(
[
DeviceOrientation.portraitUp, // 竖屏 Portrait 模式
// DeviceOrientation.portraitDown,
// DeviceOrientation.landscapeLeft, // 横屏 Landscape 模式
// DeviceOrientation.landscapeRight,
],
);
runApp(MyApp());
}
2 changes: 1 addition & 1 deletion lib/pages/diaries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _DiariesPagePageState extends State<DiariesPage> {

// 获取日记
_getDiaries() {
return Future.delayed(Duration(seconds: 1),() async {
return Future.delayed(Duration(seconds: 0),() async {
_diaries = await data.getDiaries();
});
}
Expand Down
44 changes: 38 additions & 6 deletions lib/pages/diary.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../pages/write_a_diary.dart';
import '../common/data.dart' as data;
import '../common/widgets.dart';

/// 浏览日记
class DiaryPage extends StatelessWidget {
Expand All @@ -14,14 +16,13 @@ class DiaryPage extends StatelessWidget {
return new Scaffold(
appBar: AppBar(
title: const Text('日记浏览'),
elevation: 0,
actions: <Widget>[
// 删除按钮
IconButton(
icon: Icon(Icons.delete),
onPressed: () {
_delete(context);
}),
}),
],
),

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

// 内容
Expanded(child: Text(
_data["content"],
style: TextStyle(fontSize: 18,),
),),
Expanded(child: SingleChildScrollView(
child: Text(
_data["content"],
style: TextStyle(fontSize: 18,),
),
)),

SizedBox(height: 10),// 保留间距

// 编辑按钮
Padding(
padding: EdgeInsets.fromLTRB(100, 5, 100, 0),
child: GradientButton(
colors: [Color(0xFFFF7E5F), Color(0xFFFFAD77)],
splashColor: Color(0xFFFF7E5F),
onPressed: () {
Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
return new WriteADiaryPage(
id: _data["id"],
content: _data["content"],
title: _data["title"],
);
})).then((value) => Navigator.pop(context, "refresh"));
},
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.edit, color: Colors.white,),
SizedBox(width: 10),// 保留间距
Text("编辑")
],
),
borderRadius: BorderRadius.circular(100),
),
)
],
)
)
Expand Down
108 changes: 57 additions & 51 deletions lib/pages/help.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,58 +28,64 @@ class _HelpPageState extends State<HelpPage> {
builder: (BuildContext context, AsyncSnapshot<void> snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.done: // 执行完成
return new Column(
children: [
new RichText(
text: TextSpan(
children: [
TextSpan(
text: '介绍\n',
style: Theme.of(context).primaryTextTheme.headline6,
),
TextSpan(
text: '《Murmurer》是一款用来记录生活的软件。\n\n',
style: TextStyle(color: Colors.black),
),
TextSpan(
text: '关于\n',
style: Theme.of(context).primaryTextTheme.headline6,
),
TextSpan(
text: '作者:',
style: TextStyle(color: Colors.black),
),
TextSpan(
text: '珒陶(陈锦涛)\n',
style: TextStyle(color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () {
launch('http://www.chenjt.com/');
},
),
TextSpan(
text: '版本:${_packageInfo.version}\n',
style: TextStyle(color: Colors.black),
),
TextSpan(
text: '数据库文件路径:${data.dbFilePath}\n',
style: TextStyle(color: Colors.black),
),
],
)
),
return Padding(
padding: EdgeInsets.all(20),
child: Column(
children: [
new Image(
image: AssetImage("assets/images/icon.png"),
height: 150,
),
new RichText(
text: TextSpan(
children: [
TextSpan(
text: '介绍\n',
style: Theme.of(context).primaryTextTheme.headline6,
),
TextSpan(
text: '《Murmurer》是一款用来记录生活的软件。\n\n',
style: TextStyle(color: Colors.black),
),
TextSpan(
text: '关于\n',
style: Theme.of(context).primaryTextTheme.headline6,
),
TextSpan(
text: '作者:',
style: TextStyle(color: Colors.black),
),
TextSpan(
text: '珒陶(陈锦涛)\n',
style: TextStyle(color: Colors.blue),
recognizer: TapGestureRecognizer()
..onTap = () {
launch('http://www.chenjt.com/');
},
),
TextSpan(
text: '版本:${_packageInfo.version}\n',
style: TextStyle(color: Colors.black),
),
TextSpan(
text: '数据库文件路径:${data.dbFilePath}\n',
style: TextStyle(color: Colors.black),
),
],
)
),

Divider(),

ListTile(
title: Text("许可"),//Text("Licenses"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: (){showLicensePage (
context: context,
);},
),
],
);
Divider(),
//AboutListTile(),
ListTile(
title: Text("许可"),//Text("Licenses"),
trailing: Icon(Icons.keyboard_arrow_right),
onTap: (){showLicensePage (
context: context,
);},
),
],
));
default: // 未执行完成等情况
return Container();
}
Expand Down
15 changes: 0 additions & 15 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ class HomePage extends StatelessWidget {
child: Text("写一篇日记", style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),),
borderRadius: BorderRadius.circular(20.0),
),
/*ElevatedButton(
child: Text("写一篇日记"),
onPressed: () {
writeADiary(context);
},
style: ElevatedButton.styleFrom(
primary: Color(0xFFE75A48),
minimumSize: Size(double.infinity, double.infinity),
textStyle:
TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(20.0),
),
),
),*/
),
),
],
Expand Down
Loading

0 comments on commit 9dcf2a4

Please sign in to comment.