所有路线之前的条件

问题描述

我可以在所有路线之前做一个全局条件吗?我的意思是

library giphy_picker;

import 'dart:async';
import 'package:Flutter/material.dart';
import 'package:giphy_client/giphy_client.dart';
import 'package:giphy_picker/src/widgets/giphy_context.dart';
import 'package:giphy_picker/src/widgets/giphy_search_page.dart';

export 'package:giphy_picker/src/widgets/giphy_image.dart';

typedef ErrorListener = void Function(dynamic error);

/// Provides Giphy picker functionality.
class GiphyPicker {
  /// Renders a full screen modal dialog for searching,and selecting a Giphy image.
  static Future<GiphyGif> pickGif({
    @required BuildContext context,@required String apiKey,String rating = Giphyrating.g,String lang = GiphyLanguage.english,Widget title,ErrorListener onError,bool showPreviewPage = true,String searchText = 'Search GIPHY',}) async {
    GiphyGif result;

    await Navigator.push(
        context,MaterialPageRoute(
            builder: (BuildContext context) => GiphyContext(
                  child: GiphySearchPage(),apiKey: apiKey,rating: rating,language: lang,onError:
                      onError ?? (error) => _showErrorDialog(context,error),onSelected: (gif) {
                    result = gif;

                    // pop preview page if necessary
                    if (showPreviewPage) {
                      Navigator.pop(context);
                    }
                    // pop giphy_picker
                    Navigator.pop(context);
                  },showPreviewPage: showPreviewPage,searchText: searchText,),fullscreenDialog: true));

    return result;
  }

  static void _showErrorDialog(BuildContext context,dynamic error) {
    showDialog(
      context: context,builder: (BuildContext context) {
        return AlertDialog(
          title: new Text('Giphy error'),content: new Text('An error occurred. $error'),actions: <Widget>[
            new FlatButton(
              child: new Text("Close"),onpressed: () {
                Navigator.of(context).pop();
              },],);
      },);
  }
}

,但不是针对特定模块,而是针对服务器收到的每个请求。我需要验证标题是否正确。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)