Skip to content

Commit

Permalink
fix: 修复不登陆还显示同步成功的提示
Browse files Browse the repository at this point in the history
  • Loading branch information
meowrain committed Oct 13, 2024
1 parent 1621248 commit ab24507
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions lib/src/views/todolist/todolist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -26,16 +27,30 @@ class _TodoListState extends State<TodoList> {
}

Future<void> _refreshTodos() async {
await context.read<Todoprovider>().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<AuthStatusprovider>(context, listen: false);
if (authStatusprovider.isLoggedIn) {
await context.read<Todoprovider>().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
Expand Down

0 comments on commit ab24507

Please sign in to comment.