Skip to content

Commit 645865d

Browse files
committed
feat: chears! finish the template of Diary of developing.
Now it can be supposed to sync Diary to Notion.
1 parent d54cab1 commit 645865d

File tree

6 files changed

+59
-37
lines changed

6 files changed

+59
-37
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Shorey是一款笔记应用, 支持Android/iOS双平台, 使用Flutter <strike>2
99

1010
后边会先开发联动Notion, 让你的Notion成为后台知识库.
1111

12-
Shorey is a simple note app which is built with Flutter <strike>2</strike> 3 and supports both Android/iOS platforms. It provides me full experience of interacting with Flutter and in the meantime I hope it can be your knowledge/memory transition tool, and yes, there still much work to do.
12+
Shorey is a simple note app which is built with Flutter <strike>2</strike> 3 and supports both Android/iOS platforms. It provides me full experience of interacting with Flutter and in the meantime I hope it can be your knowledge/memory transition tool, and yes, there are still much work to do.
1313

1414
Now I focus on linking Notion, in order to make Notion your backend knowledge database.
1515

@@ -35,11 +35,11 @@ Now I focus on linking Notion, in order to make Notion your backend knowledge da
3535
## 马上开始
3636
**应用运行要求:**
3737
1. Android 5.0+
38-
2. iOS 10+
38+
2. iOS 11+
3939

4040
**项目编译要求:**
41-
1. Android SDK 28/Xcode 13
42-
2. Flutter SDK 3.0.4
41+
1. Android SDK 28/Xcode 14
42+
2. Flutter SDK 3.10
4343

4444
## 应用展示
4545
UI部分大量参考了Flutter官方的Gallery应用. 此外还在关于页埋了个小彩蛋, 希望喜欢.

assets/json/notion_diary_item.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
}
1313
]
1414
},
15+
"Date": {
16+
"date": {
17+
"start": ""
18+
}
19+
},
1520
"Location": {
1621
"rich_text": [
1722
{

lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ void _configHttpClient() {
8080
dio.options.baseUrl = 'https://api.notion.com/';
8181
dio.options.headers.addAll({'Notion-Version': notionApiVersion});
8282
dio.options.connectTimeout = Duration(seconds: 5);
83-
dio.options.receiveTimeout = Duration(seconds: 7);
84-
(dio.transformer as DefaultTransformer).jsonDecodeCallback = parseJson;
83+
dio.options.receiveTimeout = Duration(seconds: 20);
84+
(dio.transformer as BackgroundTransformer).jsonDecodeCallback = parseJson;
8585
}
8686

8787
void _configLoading() {

lib/model/notion_database_template.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ class NotionDatabaseTemplate {
3434
static const String jTypeChildren = 'children';
3535
static const String jTypeObject = 'object';
3636
static const String jTypeParagraph = 'paragraph';
37+
static const String jTypeImage = 'image';
3738
static const String jTypeDate = 'date';
3839
static const String jTypeStart = 'start';
3940
static const String jTypeEnd = 'end';
4041
static const String jTypeRichText = 'rich_text';
4142
static const String jTypeCreatedTime = 'created_time';
43+
static const String jTypeExternal = 'external';
44+
static const String jTypeUrl = 'url';
4245

4346
static const String jStatus = 'Status';
4447
static const String jBrief = 'Brief';
4548
static const String jName = 'Name';
49+
static const String jDate = 'Date';
4650
static const String jTags = 'Tags';
4751
static const String jDuration = 'Duration';
4852
static const String jReminderTime = 'Reminder Time';
@@ -137,19 +141,25 @@ class NotionDatabaseTemplate {
137141
String? location,
138142
String? weather,
139143
String? brief,
144+
String? weatherUploadUrl,
145+
String? date,
140146
List<String>? tags,
141147
}) async {
142148
final json = await rootBundle.loadString(jsonDiaryItem);
143149
if (json != null) {
144150
final map = jsonDecode(json);
145151
map[jParent][jDatabaseId] = databaseId;
146152
map[jProperties][jName][jTypeTitle][0][jTypeText][jTypeContent] = title;
153+
map[jProperties][jDate][jTypeDate][jTypeStart] = date;
147154
map[jProperties][jTags][jTypeMultiSelect][0][jTypeName] = tags?[0];
148-
map[jProperties][jLocation][jTypeRichText][0][jTypeText][jTypeContent] = location;
149-
map[jProperties][jWeather][jTypeRichText][0][jTypeText][jTypeContent] = weather;
155+
map[jProperties][jLocation][jTypeRichText][0][jTypeText][jTypeContent] =
156+
location;
157+
map[jProperties][jWeather][jTypeRichText][0][jTypeText][jTypeContent] =
158+
weather;
150159
map[jTypeChildren][0][jTypeParagraph][jTypeRichText][0][jTypeText]
151160
[jTypeContent] = brief;
152-
161+
map[jTypeChildren][1][jTypeImage][jTypeExternal][jTypeUrl] =
162+
weatherUploadUrl;
153163
return map;
154164
}
155165
return null;

lib/pages/add_new_item_page.dart

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ class _AddNewItemPageState extends State<AddNewItemPage>
7878
int? _notificationId;
7979
String? _weather;
8080
String? _location;
81+
String? _bannerUploadUrl;
8182

8283
@override
8384
void initState() {
8485
super.initState();
85-
TimeOfDay _timeOfDay = TimeOfDay.now().replacing(hour: TimeOfDay.now().hour + 1);
86+
TimeOfDay _timeOfDay =
87+
TimeOfDay.now().replacing(hour: TimeOfDay.now().hour + 1);
8688
_time = dy.Time.fromTimeOfDay(_timeOfDay, 60);
8789
_categoryId = widget.category.id;
8890
if (widget.title != null) {
@@ -172,19 +174,17 @@ class _AddNewItemPageState extends State<AddNewItemPage>
172174
setState(() {});
173175
Fluttertoast.showToast(msg: S.of(context).cancelAlertTime);
174176
}),
175-
Consumer<NewItemViewModel>(
176-
builder: (context, _, __) {
177-
return IconButton(
178-
icon: Icon(
179-
Icons.check,
180-
color: colorScheme.onSecondary,
181-
),
182-
onPressed: () async {
183-
_syncWithNotion(await _saveItem(context));
184-
Navigator.pop(context, 0);
185-
});
186-
}
187-
),
177+
Consumer<NewItemViewModel>(builder: (context, _, __) {
178+
return IconButton(
179+
icon: Icon(
180+
Icons.check,
181+
color: colorScheme.onSecondary,
182+
),
183+
onPressed: () async {
184+
_syncWithNotion(context, await _saveItem(context));
185+
Navigator.pop(context, 0);
186+
});
187+
}),
188188
],
189189
),
190190
body: Container(
@@ -197,7 +197,8 @@ class _AddNewItemPageState extends State<AddNewItemPage>
197197
margin: EdgeInsets.symmetric(horizontal: 16),
198198
height: 400,
199199
decoration: BoxDecoration(
200-
borderRadius: BorderRadius.circular(8), color: Colors.white),
200+
borderRadius: BorderRadius.circular(8),
201+
color: Colors.white),
201202
child: Column(
202203
children: [
203204
InputField(
@@ -227,6 +228,11 @@ class _AddNewItemPageState extends State<AddNewItemPage>
227228
onInfoUpdated: (weather, temp, location) {
228229
_weather = '$weather $temp℃';
229230
_location = location;
231+
// if (weather!.isNotEmpty &&
232+
// _location != null &&
233+
// _bannerUploadUrl != null) {
234+
// //_prepareDiaryBannerPic(context);
235+
// }
230236
},
231237
)),
232238
),
@@ -255,7 +261,6 @@ class _AddNewItemPageState extends State<AddNewItemPage>
255261

256262
Future _saveItem(BuildContext context) async {
257263
if (widget.category.notionDatabaseType == ActionType.DIARY) {
258-
await _prepareDiaryBannerPic(context);
259264
_companion = ToDosCompanion(
260265
categoryId: d.Value(_categoryId),
261266
content: d.Value(_titleController.text),
@@ -265,7 +270,8 @@ class _AddNewItemPageState extends State<AddNewItemPage>
265270
tags: d.Value(_categoryName),
266271
thumb: d.Value(_thumb),
267272
weather: d.Value(_weather),
268-
location: d.Value(_location));
273+
location: d.Value(_location),
274+
weatherBannerUrl: d.Value(_bannerUploadUrl));
269275
} else {
270276
await _prepareReminderTime();
271277
_companion = ToDosCompanion(
@@ -290,13 +296,12 @@ class _AddNewItemPageState extends State<AddNewItemPage>
290296
var image = await boundary.toImage(pixelRatio: 3.0);
291297
ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
292298
Uint8List? imageBuffer = byteData?.buffer.asUint8List();
293-
294-
final Response res = await context.read<NewItemViewModel>().uploadImage(byteData);
295-
296299
if (imageBuffer != null) {
297300
_thumb = base64.encode(imageBuffer);
298301
}
299-
//imageBuffer = base64.decode(base64.encode(imageBuffer!));
302+
final Response res =
303+
await context.read<NewItemViewModel>().uploadImage(byteData);
304+
_bannerUploadUrl = res.data;
300305
}
301306

302307
Future _prepareReminderTime() async {
@@ -315,12 +320,14 @@ class _AddNewItemPageState extends State<AddNewItemPage>
315320
}
316321
}
317322

318-
Future<void> _syncWithNotion(int index) async {
323+
Future<void> _syncWithNotion(BuildContext context, int index) async {
319324
if (widget.category.notionDatabaseId != null &&
320325
context.read<ConfigViewModel>().linkedNotion &&
321326
_companion != null) {
322-
323-
final pageId = await context.read<NotionWorkFlow>().addTaskItem(
327+
if(_notionDatabaseType == ActionType.DIARY){
328+
await _prepareDiaryBannerPic(context);
329+
}
330+
final pageId = await appContext.read<NotionWorkFlow>().addTaskItem(
324331
widget.category.notionDatabaseId!,
325332
ToDo(
326333
id: 0,
@@ -334,6 +341,7 @@ class _AddNewItemPageState extends State<AddNewItemPage>
334341
weather: _weather,
335342
location: _location,
336343
thumb: _thumb,
344+
weatherBannerUrl: _bannerUploadUrl
337345
),
338346
actionType: _notionDatabaseType!);
339347
if (index != -1) {

lib/workflow/notion_workflow.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,17 @@ class _DiaryActions extends NotionActions {
250250
@override
251251
Future<String?> addItem(String databaseId, ToDo todo,
252252
{List<String>? links,}) async {
253-
if(todo.thumb !=null && todo.thumb!.isNotEmpty){
254-
255-
}
256-
257253

258254
final param = await NotionDatabaseTemplate.diaryItem(
259255
databaseId,
260256
title: todo.content,
257+
date: todo.createdTime.toIso8601String(),
261258
brief: todo.brief ?? '',
262259
tags: ['${todo.tags}'],
263260
location: todo.location ?? '',
264261
weather: todo.weather ?? '',
262+
weatherUploadUrl: todo.weatherBannerUrl??'',
263+
265264
);
266265
final response = await dio.post('${notionPages}', data: param);
267266
if (response.success) {

0 commit comments

Comments
 (0)