Flutter:我如何navigator.pop?

时间:2019-03-31 14:59:13

标签: dart flutter bloc

我正在使用Flutter开发一个简单的待办事项应用程序。

它具有待办事项列表用户界面,如果用户单击其中之一,则会显示详细信息用户界面。

详细信息用户界面具有删除按钮。 因此,当用户单击按钮时,应该删除待办事项并将UI移回到上一个UI(Todo列表UI)。

我正在使用BloC模式。

class DetailsTodo extends StatelessWidget {

  final TodoRepository _todoRepository;
  final String _todoId;
  final DetailsTodoBloc bloc;

  DetailsTodo(this._todoRepository, this._todoId)
      : this.bloc = DetailsTodoBloc(_todoRepository, _todoId);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: StreamBuilder<Todo>(
            stream: bloc.todo,
            builder: (context, snapshot) {
              final todo = snapshot.data;
              print("[DetailsTodo][JOS] todo: $todo");
              return Text(todo.name);
            }),
      ),
    );
  }

这是BloC:

class DetailsTodoBloc {
  final TodoRepository _todoRepository;
  final String _todoId;

  final _getTodoSubject = PublishSubject<Todo>();

  final _deleteTodSubject = PublishSubject<String>();

  Stream<Todo> get todo => _getTodoSubject.stream;

  Sink<String> get delete => _deleteTodSubject.sink;

  DetailsTodoBloc(this._todoRepository, this._achievementRepository, this._todoId) {
    _getTodo();
    _deleteTodSubject.listen(_deleteTodo);
  }

  Future<Null> _getTodo() async {
    final todo = await _todoRepository.get(_todoId);
    _getTodoSubject.add(todo);
  }


  void _deleteTodo(String todoId) async {
    final result = await _todoRepository.delete(todoId);
    _getTodoSubject.add(null); // I want to notify to the UI to call "Navigator.pop". But I don't know how to do it.
  }
}

完成待办事项删除后,我不知道如何调用“ Navigator.pop”。

0 个答案:

没有答案