From ab24507d8529a898050ce481e3bb5c8a537aa4d3 Mon Sep 17 00:00:00 2001 From: meowrain Date: Sun, 13 Oct 2024 13:38:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8D=E7=99=BB?= =?UTF-8?q?=E9=99=86=E8=BF=98=E6=98=BE=E7=A4=BA=E5=90=8C=E6=AD=A5=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E7=9A=84=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/views/todolist/todolist.dart | 35 ++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/src/views/todolist/todolist.dart b/lib/src/views/todolist/todolist.dart index 841b931..88d1228 100644 --- a/lib/src/views/todolist/todolist.dart +++ b/lib/src/views/todolist/todolist.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:todo_app/src/components/dialog_box.dart'; import 'package:todo_app/src/models/todo/todo.dart'; +import 'package:todo_app/src/providers/authStatusProvider.dart'; import 'package:todo_app/src/providers/todoProvider.dart'; import 'package:todo_app/src/views/todotile/todotile.dart'; @@ -26,16 +27,30 @@ class _TodoListState extends State { } Future _refreshTodos() async { - await context.read().syncTodoListProvider(); - ScaffoldMessenger.of(context).showSnackBar(const SnackBar( - content: Text( - "同步成功!", - style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white), - ), - behavior: SnackBarBehavior.floating, - duration: Duration(seconds: 1), - backgroundColor: Colors.green, - )); + final AuthStatusprovider authStatusprovider = + Provider.of(context, listen: false); + if (authStatusprovider.isLoggedIn) { + await context.read().syncTodoListProvider(); + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text( + "同步成功!", + style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white), + ), + behavior: SnackBarBehavior.floating, + duration: Duration(seconds: 1), + backgroundColor: Colors.green, + )); + } else { + ScaffoldMessenger.of(context).showSnackBar(const SnackBar( + content: Text( + "请先登录再使用同步功能", + style: TextStyle(fontWeight: FontWeight.bold, color: Colors.white), + ), + behavior: SnackBarBehavior.floating, + duration: Duration(seconds: 1), + backgroundColor: Colors.red, + )); + } } @override