小编pri*_*oo7的帖子

固定错误:如何解决返回类型 'StreamController<ConnectivityStatus>' is not a 'Stream',由匿名关闭错误定义

我正在按照以下教程了解基于互联网连接的连接状态。

链接:https : //www.filledstacks.com/post/make-your-flutter-app-network-aware-using-provider-and-connectivity-status/

现在的问题是,那么我正在尝试实现代码。在我使用 StreamProvider 的过程结束时,在构建器中我收到以下错误:

错误:返回类型“StreamController”不是匿名闭包定义的“Stream”。

代码如下:main.dart

@override
  Widget build(BuildContext context) {
      return StreamProvider(
        builder:  (context) => ConnectivityService().connectionStatusController, // ERROR LINE
        child: ChangeNotifierProvider<ThemeChanger>(
          builder: (_) => ThemeChanger((x) ? ThemeChanger.customDarkTheme : ThemeChanger.customLightTheme),
          child: new MaterialAppWithTheme(),
        ),
      );
  }
}

Run Code Online (Sandbox Code Playgroud)

用作者的 git 代码完全替换我的类型代码,链接如下:https : //github.com/FilledStacks/flutter-tutorials/tree/master/011-network-sensitive-ui/

我试过谷歌搜索,但对我的情况没有用。我的代码出了什么问题?是因为我在使用另一个供应商吗?


自我发现的解决方案的更新答案


@override
  Widget build(BuildContext context) {
      return StreamProvider(
        builder:  (context) => ConnectivityService().connectionStatusController.stream, // add .stream at end
        child: ChangeNotifierProvider<ThemeChanger>(
          builder: (_) => ThemeChanger((x) ? ThemeChanger.customDarkTheme : ThemeChanger.customLightTheme),
          child: new MaterialAppWithTheme(),
        ),
      ); …
Run Code Online (Sandbox Code Playgroud)

status connectivity mobile-application flutter

11
推荐指数
1
解决办法
2368
查看次数

如何根据设置的主题更改flutter中的状态栏图标和文本颜色?

如何在没有任何第三方插件的情况下更新状态栏图标的颜色?

在我的主题课程中,我有一个函数,我正在尝试下面的代码,但尚未实现结果:

目前的主题代码:


// custom light theme for app
  static final customLightTheme = ThemeData.light().copyWith(
    brightness: Brightness.light,
    primaryColor: notWhite,
    accentColor: Colors.amberAccent,
    scaffoldBackgroundColor: notWhite,
    primaryTextTheme: TextTheme(
      title: TextStyle(
        color: Colors.black
      ),

    ),
    appBarTheme: AppBarTheme(
      iconTheme: IconThemeData(color: Colors.black),
      elevation: 0.0,
    )
  );

  // custom dark theme for app
  static final customDarkTheme = ThemeData.dark().copyWith(
    brightness: Brightness.dark,
    primaryColor: Colors.black,
      accentColor: Colors.orange,
      scaffoldBackgroundColor: Colors.black87,
      primaryTextTheme: TextTheme(
        title: TextStyle(
            color: Colors.white
        ),

      ),
      appBarTheme: AppBarTheme(
        iconTheme: IconThemeData(color: Colors.white),
        elevation: 0.0,
      ),

  );

Run Code Online (Sandbox Code Playgroud)

主题更改代码:


// set theme for …
Run Code Online (Sandbox Code Playgroud)

user-interface android statusbar ios flutter

7
推荐指数
3
解决办法
1万
查看次数

how to get html content form flutterWebViewPlugin ( webview ) in flutter

My question is pretty simple. how can I get the html data form the loaded page in webview. The data is in JSON format. for a reason I cannot use a post request for any get request here so I need to get the data with webview only. how to achive this ?

flutterWebViewPlugin.onUrlChanged.listen((String url) {
      if (url.contains('/recon?')) {
        print('printing url : $url');
        // need to get data ( html content ) on this url
        flutterWebViewPlugin.close();
        Navigator.of(context).pop(url);
      }
    });
}); …
Run Code Online (Sandbox Code Playgroud)

json webview flutter

6
推荐指数
3
解决办法
7843
查看次数

在flutter中使用video_player插件时如何显示视频的当前播放时间?

当前使用video_player来自给定链接的 flutter插件流视频。问题是我不得不隐藏正常的视频交互界面,以便用户无法跳过视频。现在大部分工作已经完成,只需要知道如何显示durationcurrent position播放的视频。

videoController.value.duration.inSeconds给我duration部分,并videoController.value.positionposition. But how to keep updating the results for the位置`部分?

void checkTimer(){
    if(playerController.value.position == playerController.value.duration){
      setState(() {
        Duration duration = Duration(milliseconds: playerController?.value?.position?.inMilliseconds?.round());

      nowTime = [duration.inHours, duration.inMinutes, duration.inSeconds]
        .map((seg) => seg.remainder(60).toString().padLeft(2, '0'))
        .join(':');
      });
    }

Run Code Online (Sandbox Code Playgroud)

创建上面的代码是为了根据需要更新时间。但现在的问题是如何更新时间。我应该使用setState()还是其他东西,因为上面的代码对我不起作用。

视频未加载,然后屏幕加载。然后当用户单击播放按钮时加载它。所以直到那个时候,我们甚至没有duration价值,因为数据还在路上。

video plugins position video-player flutter

1
推荐指数
1
解决办法
2983
查看次数