flutter

Flutter 父组件调用子组件方法

其实主要就是在初始化子控件的时候传递一个GlobalKey 然后用这个key调用子控件的函数。只贴核心代码,其中 onPressed 是子控件函数。 // 子组件 SonWidget(Key key) : super(key: key); // 父组件 GlobalKey<SonWidgettState> SonKey = GlobalKey(); //设置key,绑定待刷新控件. 初始化控件 SonWidget(SonKey) 调用子空间函数 SonKey.currentState.onPressed( _count);  

Flutter 子组件调用父组件函数

 在子组件内定义回调函数名称 ChildView({this.changeColorCallBack}); final ValueChanged<Color> changeColorCallBack; 注意ValueChanged要指定泛型 在父组件使用 child: ChildView(changeColorCallBack: (color) { setState(() { _myColor = color; }); },)

flutter 启动前加载本地json配置文件 报错 Unhandled Exception: Null check operator used on a null value

想在启动的时候使用rootBundle.loadString 加载本地配置json,但是直接加载会 报错: [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value   解决办法:加载本地资源以前增加一行代码: WidgetsFlutterBinding.ensureInitialized(); //解决加载json错误 例子: void main() async { WidgetsFlutterBinding.ensureInitialized(); //解决加载json错误 globals.config = jsonDecode(await rootBundle.loadString('assets/config.json')); runApp(MyApp()); }

flutter 编译报错 uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library

废话不多说 路径:android\app\build.gradle minSdkVersion 16 修改为 minSdkVersion 19

flutter 报错 Could not resolve io.flutter:flutter_embedding_release

 我是升级flutter后,所有项目都报错,先贴解决办法: flutter\packages\flutter_tools\gradle 目录下 aar_init_script.gradle resolve_dependencies.gradle flutter.gradle 以上三个文件中将 http://download.flutter.io 替换为: https://storage.googleapis.com/download.flutter.io   报错如下: flutter build apk The plugin `flutter_forbidshot` is built using an older version of the Android plugin API which assumes that it's running in a full-Flutter environment. It may have undefined behaviors when Flutter is integrated into an e...

flask模板使用layui前端框架语法冲突

 大致报错如下吧. {{ 很容易冲突.  File "D:\soft\Python27\lib\site-packages\jinja2\environment.py", line 804, in _load_template template = self.loader.load(self, name, globals) File "D:\soft\Python27\lib\site-packages\jinja2\loaders.py", line 125, in load code = environment.compile(source, name, filename) File "D:\soft\Python27\lib\site-packages\jinja2\environment.py", line 591, in compile self.handle_exception(exc_info, source_hint=source_hint) File "D:\sof...

运行卡在flutter packages get: running…

F5调试的时候 卡在 flutter packages get: running... 好久,看输出日志 应该是官网北墙,官方也注意到了这个问题. 提供了中国的镜像,我们只需新增系统变量 PUB_HOSTED_URL 和 FLUTTER_STORAGE_BASE_URL 两个参数,并分别设置URL 即可. PUB_HOSTED_URL=https://pub.flutter-io.cn FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn 设置完毕执行: flutter doctor   下面是linux操作办法 export PUB_HOSTED_URL=https://pub.flutter-io.cn export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn git clone -b dev https://github.com/flutter/flutter.git export PATH=&qu...

D8: Invoke-customs are only supported starting with Android O (–min-api 26)

 在\android\app\build.gradle中添加以下内容: compileOptions { sourceCompatibility JavaVersion.VERSION_1_8     targetCompatibility JavaVersion.VERSION_1_8 } 如下: android { compileSdkVersion 27 lintOptions { disable 'InvalidPackage' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.xyvod" minSdkVersion 16 targetSdkVersion 27 versionCode flutterVersionCod...

Flutter 集成 Python

  This example shows how to run python script from flutter. This example is based on starcore_for_flutter, which enables flutter calls other scripts. Step by Step 1. Create flutter project $ flutter create flutter_python 2. Add dependency package “starflut” and assets folder Edit “pubspec.yaml” dependencies: flutter: sdk: flutter starflut: any ... # To add assets to your application, add an assets section, like this: a...

flutter_webview_plugin 插件的安装与引用

flutter 引用 webview 插件步骤 1. 添加插件依赖 编辑 pubspec.yaml 文件,在dependencies:下增加一行: flutter_webview_plugin: ^0.3.0+2 例子: dependencies: flutter_webview_plugin: ^0.3.0+2 2. 安装 执行下面命令安装插件,如果是 vscode 保存文件后会自动安装 $ flutter packages get 3.引入插件 文件头部增加 import 'package:flutter_webview_plugin/flutter_webview_plugin.dart'; 参考网址: https://pub.dartlang.org/packages/flutter_webview_plugin#-installing-tab-