我正在按照以下教程了解基于互联网连接的连接状态。
链接: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) 如何在没有任何第三方插件的情况下更新状态栏图标的颜色?
在我的主题课程中,我有一个函数,我正在尝试下面的代码,但尚未实现结果:
目前的主题代码:
// 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) 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) 当前使用video_player来自给定链接的 flutter插件流视频。问题是我不得不隐藏正常的视频交互界面,以便用户无法跳过视频。现在大部分工作已经完成,只需要知道如何显示duration和current position播放的视频。
videoController.value.duration.inSeconds给我duration部分,并videoController.value.position给position. 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价值,因为数据还在路上。