Flutter常用代码及命令
命令
运行:
flutter run
(默认为debug环境)
flutter run --release
(以release模式运行)
帮助:flutter -h
或 flutter --help
诊断flutter:flutter doctor
查看flutter版本号:flutter --version
flutter升级:flutter upgrade
获取flutter packages包:flutter packages get
json序列化,自动监听命令(使用json_annotation、build_runner、json_serializable库的执行命令):
flutter packages pub run build_runner watch
打包apk包:
64位-release:
flutter build apk --release --target-platform android-arm64
32位-release:
flutter build apk --release --target-platform android-arm
查看flutter当前版本:flutter channel
切换flutter版本的master:flutter channel master
创建flutter项目
flutter create --ios-language swift --android-language kotlin --org net.yzjlb --project-name shadowcamera ./shadowcamera
创建插件
flutter create --template=plugin --org com.example --platform=android,ios -i swift -a java hello
-h, --help Print this usage information.
-v, --verbose Noisy logging, including all shell commands executed.
If used with --help, shows hidden options.
-d, --device-id Target device id or name (prefixes allowed).
--version Reports the version of this tool.
--suppress-analytics Suppress analytics reporting when this command runs.
--packages Path to your ".packages" file.
(required, since the current directory does not contain a ".packages" file)
Usage: flutter create <output directory>
-h, --help Print this usage information.
--platforms The platforms supported by this project. This argument only works when the --template is
set to app or plugin. Platform folders (e.g. android/) will be generated in the target
project. When adding platforms to a plugin project, the pubspec.yaml will be updated with
the requested platform. Adding desktop platforms requires the corresponding desktop
config setting to be enabled.
[ios (default), android (default), windows (default), linux (default), macos (default),
web (default)]
--[no-]pub Whether to run "flutter pub get" after the project has been created.
(defaults to on)
--[no-]offline When "flutter pub get" is run by the create command, this indicates whether to run it in
offline mode or not. In offline mode, it will need to have all dependencies already
available in the pub cache to succeed.
--[no-]with-driver-test Also add a flutter_driver dependency and generate a sample 'flutter drive' test.
-t, --template=<type> Specify the type of project to create.
[app] (default) Generate a Flutter application.
[module] Generate a project to add a Flutter module to an existing Android or iOS application.
[package] Generate a shareable Flutter project containing modular Dart code.
[plugin] Generate a shareable Flutter project containing an API in Dart code with a
platform-specific implementation for Android, for iOS code, or for both.
-s, --sample=<id> Specifies the Flutter code sample to use as the main.dart for an application. Implies
--template=app. The value should be the sample ID of the desired sample from the API
documentation website (http://docs.flutter.dev). An example can be found at
https://master-api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html
--list-samples=<path> Specifies a JSON output file for a listing of Flutter code samples that can be created
with --sample.
--[no-]overwrite When performing operations, overwrite existing files.
--description The description to use for your new Flutter project. This string ends up in the
pubspec.yaml file.
(defaults to "A new Flutter project.")
--org The organization responsible for your new Flutter project, in reverse domain name
notation. This string is used in Java package names and as prefix in the iOS bundle
identifier.
(defaults to "com.example")
--project-name The project name for this new Flutter project. This must be a valid dart package name.
-i, --ios-language [objc, swift (default)]
-a, --android-language [java, kotlin (default)]
跳转到指定界面
Navigator.push(context, new MaterialPageRoute(builder: (context) {
return new RegisteredWidget();
}));
界面返回
Navigator.pop();
//显示dialog
//常用的脚手架
Scaffold
ScrollView嵌套GridView滚动冲突问题,设置GridView的shrinkWrap: true,
shrinkWrap: true,
//实现widget的点击事件
InkResponse(
child:...,
onTap:()=>{},
)
//给按钮加圆角背景
//给按钮加图片背景
//修改输入框光标及去除背景
解决界面返回黑屏问题
https://blog.csdn.net/yuzhiqiang_1993/article/details/89090742
Flutter 问题解决总结
https://juejin.im/post/5c91a8da5188252db75696c0
TextField属性详解
https://blog.csdn.net/weixin_34273479/article/details/87172605
Flutter之BaseWidget高度封装
https://blog.csdn.net/iamdingruihaha/article/details/88319883
http封装
https://blog.csdn.net/iamdingruihaha/article/details/88865590
flutter使用swiper
https://juejin.im/post/5c3f3c29f265da6120621048
显示toast
显示dialog
有多个滚动视图的情况
shrinkWrap: true,
flutter 错误汇总:
ScrollController attached to multiple scroll views.
ScrollController not attached to any scroll views.
flutter Container设置背景阴影 card
Container(
// color: Colors.white,
padding: EdgeInsets.fromLTRB(4, 8, 4, 1),
margin: EdgeInsets.fromLTRB(6, 6, 6, 6),
// elevation: 1,
// shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4))), //设置圆角
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4)),
// color: Colors.blue,
// border: new Border.all(color: Color(0xFFFF0000), width: 8,),
// 边色与边宽度
boxShadow: [
BoxShadow(
color: Color(0x20000000),
offset: Offset(0, 4),
blurRadius: 1,
spreadRadius: -4),
],
),
)
flutter定义图片矩形区域拉伸(点九图)
centerSlice: new Rect.fromLTRB(
270.0, 180.0, 1360.0, 730.0),
),
实现左上和右上圆角的boxdecoration
BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
),
Flutter 启用web
flutter config --enable-web
Flutter 创建web
flutter create --web .