@@ -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 ) {
0 commit comments