Flutter 爬坑记录(转)

1.命令行运行flutter run之后iOS报错:
Could not install build/ios/iphones/Runner.app on XXXXX. try lunching Xcode and
selecting "Project > Run" to fix the problem open ios/Runner.xworkspace.......

这个恶心的报错,我一直以为是我Xcode的问题,因为早上一直好的,代码未动.而下午什么都没做,就是Xcode升级了下.然后就不行了.可以使用Xcode直接运行.但是命令行不行.最后发现我手机在充电,于是拔了,然后再命令行运行flutter run之后,好了!!!fuck.这报错信息也忒能了....

2.今天在学Flutter时,写一个基本的push功能时,发现代码无误,但是报个错'package: XXXX:error:Unexpected tag 128(SepecialiedVariableGet) in ?,expected a procedure,a constructor or a function node',发现在test文件夹里面有个错误,修改好之后,再次r,还是不行.没办法只能重新R.再次重新运行就好了.和当时视频中有这点区别.记录一下.

3.开发中,有时候在flutter packeages get 或者 flutter create XXX等过程中,程序中断,再次打开时,会出现Waiting for another flutter command to relsease the startup lock...

此时打开 flutter的sdk安装目录,关闭ide, 删除文件 bin/cache/lockfile即可.如下:

 4.升级Flutter时,出现:Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)

 

重现: 在flutter1.0升级flutter1.2时,中途卡住.听网友的中断再升级,运行 flutter upgrade 之后就报这错误了.

解决: 删除 flutter SDK中 bin/cache 文件夹 再 flutter upgrade就好了

5.升级flutter后,之前好的项目就不行了.这时重新 flutter packages get 获取下三方库.然后再运行就好了. why???

6.在 flutter packages get时,pub get failed:

我的原因是:版本号前面未加一个空格.

 7.最近上传代码到github老是报错,Failed to connect to 127.0.0.1 port 1080: Connection refused .....
不管FQ与否,蓝☺灯不行,ss不行,Cla☺shX不行,V☺2☺ra☺yU也不行,还整天封端口fuck....按照网上的取消git代理也不行(git config --global --unset http.proxy)
实在烦得很,直接去gitconfig删除字段!!!

第一步

在终端输入

defaults write com.apple.finder AppleShowAllFiles -boolean true ; killall Finder

这行命令可以显示电脑的隐形文件

第二步

在Finder里面个人账号的文件夹里找到gitconfig这个隐藏文件,右击打开,然后把里面的代理proxy整行删掉

8.最近在写一个Flutter项目时,发现点击跳转详情页面,底部tabbar竟然还在?!这什么鬼,出现这个情况记得3年前写iOS原生代码出现过,但那个可以配置.两年前写RN也出现过,那个只是加载顺序问题,现在写Flutter又是什么毛病,其实只是我复制代码忘记删除MaterialApp....了.一个工程只能有一个MaterialApp.不过这个bug也让我知道了一个偏方,flutter怎么写push之后还有tabbar的效果....呵呵,年纪大了,就越会安慰自己.

9.出现类似 The argument type '_BottomContainerState' can't be assigned to the parameter type 'TickerProvider'.dart(argument_type_not_assignable)

如:

这是需要混入 with SingleTickerProviderStateMixin即可.

10. children 直接遍历返回一个数组Widget: 

如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 视频标签
Widget videoTag() {
  return Container(
    child: Wrap(
        spacing: 8.0, // 主轴(水平)方向间距
        runSpacing: 4.0, // 纵轴(垂直)方向间距
        children: tag()),
  );
}
 
List<Widget> tag() {
  List<Widget> list = [];
  infoData['videoTag'].forEach((val) {
    list.add(
      ClipRRect(
        borderRadius: BorderRadius.circular(100.0),
        child: Container(
          padding: EdgeInsets.symmetric(vertical: 5.0, horizontal: 15.0),
          color: Colors.black26,
          child: Text(val),
        ),
      ),
    );
  });
  return list;
}

  

项目

 10.运行出现 

ideviceinfo returned an error:

ERROR: Could not connect to lockdownd, error code -8

连接着外接设备.移除即可

 11.add widget时,出现the method 'add' was called on null.Receiver: null.

我的错误是数组忘记初始化......

 

 11. Cannot provide both a color and adecoration.the color argument is just a shortthand for "decoration:new BoxDecoration(color: color)".

顾名思义, 意思就是这俩不能一起使用. 需要把color写入BoxDecoration里面.

 

 12.在json转model的各种工具上报格式错误........

平时使用vscode撸.使用https://javiercbk.github.io/json_to_dart/ 在线转换比较多,但是格式错误不提示...

   所以,都是先使用格式化工具格式(http://www.bejson.com/)  格式正确了在转.

   常见的错误有: 

a.

b.

 13.在拉取新库时,长时间拉取不了来.可以试试git的方式.

dependencies:
 fluro:
   git: git://github.com/theyakka/fluro.git

14.出现类似

flutter: The following assertion was thrown building SimpleDialogDemo(dirty, dependencies:

flutter: [_LocalizationsScope-[GlobalKey#61da8], _InheritedTheme], state: _SimpleDialogDemoState#4de71):

flutter: setState() or markNeedsBuild() called during build.

flutter: This Overlay widget cannot be marked as needing to build because the framework is already in the

......
如图:

错误只是在调用方法时,多写了一个()导致........果然996太久脑子容易死机.算了,记录一下.该休息一下了.

 

15.flutter的尺寸单位是dp.不是px 

16.放置2X,3X图片.

如:根目录下有images文件夹,里面有2.0x文件夹,3.0x文件夹.在images下存放1X图:xxx.png,然后在2.0x文件夹和3.0x文件夹里面也放置相应文件即可.
在pubspec.yaml直接引入 -images/xxx.png即可,flutter本身就自动识别使用2X,3X.

 

17.Android端出现:Android dependncy 'android.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath.You should manually set the same version.

我的解决办法是:

先在项目根目录下的build.gradle下把

classpath 'com.android.tools.build:gradle:3.2.1'

 改为

classpath 'com.android.tools.build:gradle:3.3.1'

然后删除
ext.kotlin_version = '1.3.31'

在grable.properties 下添加

1
2
android.useAndroidX=true
android.enableJetifier=true

之后sync 即可.

记得要FQ

文件如图所示:

 

 

 

 

其他方案: https://github.com/flutter/flutter/issues/27254 

 18.分别在iOS平台和Android平台各自添加启动图之后,启动会发生 启动图 --> 黑屏 --> 界面.

   试了好多方法均无效,最后试了下把debug改为release,好了.......艹,学艺不精就是坑

19.图片注册只需要注册到文件夹即可,不用注册到图片.如:

 20. android 模拟器出现 

Package install error: Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]
Error launching application on Android SDK built for x86.

最简单的方法就是删除几个模拟器上的app即可.

21.突然之间,Android模拟器死了.启动起来,点了点不动.flutter run -d all只有iOS起来,Android好像死了一样啥也不动,终端也不输出错误.....
之前是重新关闭,再重启模拟器就好了,最近重启模拟器也没有用,重启mac也是一样没反应.  无奈只能卸载,重新安装一个新的模拟器就好了...

22.使用输入框时,在对输入框长按操作,iOS报红,Android好的,这个恶心的问题是官方的bug,缺少对中文的支持.

我的解决办法是:

项目中添加下面这个dart文件.

common_localizations_delegate.dart

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
 
///语言(主要解决cupertino控件不能显示中文的问题)
class CommonLocalizationsDelegate
    extends LocalizationsDelegate<CupertinoLocalizations> {
  const CommonLocalizationsDelegate();
 
  @override
  bool isSupported(Locale locale) =>
      <String>['zh''CN'].contains(locale.languageCode);
 
  @override
  SynchronousFuture<_DefaultCupertinoLocalizations> load(Locale locale) {
    return SynchronousFuture<_DefaultCupertinoLocalizations>(
        _DefaultCupertinoLocalizations(locale.languageCode));
  }
 
  @override
  bool shouldReload(CommonLocalizationsDelegate old) => false;
}
 
class _DefaultCupertinoLocalizations extends CupertinoLocalizations {
  _DefaultCupertinoLocalizations(this._languageCode)
      : assert(_languageCode != null);
  final String _languageCode;
 
  static const List<String> _shortWeekdays = <String>[
    '周一',
    '周二',
    '周三',
    '周四',
    '周五',
    '周六',
    '周日',
  ];
 
  static const List<String> _shortMonths = <String>[
    '一月',
    '二月',
    '三月',
    '四月',
    '五月',
    '六月',
    '七月',
    '八月',
    '九月',
    '十月',
    '十一月',
    '十二月',
  ];
 
  static const List<String> _months = <String>[
    '一月',
    '二月',
    '三月',
    '四月',
    '五月',
    '六月',
    '七月',
    '八月',
    '九月',
    '十月',
    '十一月',
    '十二月',
  ];
 
  @override
  String get alertDialogLabel => '提醒';
 
  @override
  String get anteMeridiemAbbreviation => "上午";
 
  @override
  String get postMeridiemAbbreviation => "下午";
 
  @override
  String get copyButtonLabel => "复制";
 
  @override
  String get cutButtonLabel => "剪切";
 
  @override
  String get pasteButtonLabel => "粘贴";
 
  @override
  String get selectAllButtonLabel => "全选";
 
  @override
  DatePickerDateOrder get datePickerDateOrder => DatePickerDateOrder.ymd;
 
  @override
  DatePickerDateTimeOrder get datePickerDateTimeOrder =>
      DatePickerDateTimeOrder.date_time_dayPeriod;
 
  @override
  String datePickerDayOfMonth(int dayIndex) => dayIndex.toString();
 
  @override
  String datePickerHour(int hour) => hour.toString();
 
  @override
  String datePickerHourSemanticsLabel(int hour) => hour.toString();
 
  @override
  String datePickerMediumDate(DateTime date) {
    return '${_shortWeekdays[date.weekday - DateTime.monday]} '
        '${_shortMonths[date.month - DateTime.january]} '
        '${date.day.toString().padRight(2)}';
  }
 
  @override
  String datePickerMinute(int minute) => minute.toString().padLeft(2, '0');
 
  @override
  String datePickerMinuteSemanticsLabel(int minute) {
    if (minute == 1) return '1 分钟';
    return minute.toString() + ' 分钟';
  }
 
  @override
  String datePickerMonth(int monthIndex) => _months[monthIndex - 1];
 
  @override
  String datePickerYear(int yearIndex) => yearIndex.toString();
 
  @override
  String timerPickerHour(int hour) => hour.toString();
 
  @override
  String timerPickerHourLabel(int hour) => '时';
 
  @override
  String timerPickerMinute(int minute) => minute.toString();
 
  @override
  String timerPickerMinuteLabel(int minute) => '分';
 
  @override
  String timerPickerSecond(int second) => second.toString();
 
  @override
  String timerPickerSecondLabel(int second) => '秒';
 
  @override
  // TODO: implement todayLabel
  String get todayLabel => "今天";
}

  然后,在main.dart文件中添加

主要是 添加 CommonLocalizationsDelegate(),

 其余代码是原来配置国际化的代码.
23.出现setState() or markNeedsBuild() called during build.This XXX widget cannot be marked as needing to build because the framework is already in the process of building widgets.A widget can be marked as needing to be build during the ........

我是在输入的时候操作setState导致的,需要加一个延时即可.如:

 24.之前使用vscode撸,最近卡到飞起来,比as,xcode还卡...换回as开发,但是反括号不显示了.....

如图所示,修改一下就好了

 25.https://github.com/GigaDroid/flutter_udid 的使用: 项目中需要使用到UDID,网上找了个库,但是该库完全没有使用说明.....
该库需要iOS集成SAMKeychain. 我通过pod集成了.之后会报错:

The following Swift pods cannot yet be integrated as static libraries:

The Swift pod `flutter_udid` depends upon `SAMKeychain`, which do not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.

这个错误需要在Podfile中,

添加  use_frameworks!

然后终端会显示版本警告,要求使用8.0.

添加 platform :ios, '8.0'

最后又会报swift version版本问题,我的是Xcode10.1(swift是4.2.1)

 

 

The target “flutter_udid” contains source code developed with Swift 2.x. This version of Xcode does not support building or migrating Swift 2.x targets.

 

 Use Xcode 8.x to migrate the code to Swift 3.

我根据我的Xcode版本添加了

config.build_settings['SWIFT_VERSION'] = '4.2.1' # added this

 

之前的终于好了.  但是又会出现一个问题.问题是啥忘了.只记得解决办法是听朋友的执行 pod update.之后好了.

贴一下podfile吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Uncomment this line to define a global platform for your project
 platform :ios, '8.0'
 
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
 
project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}
 
def parse_KV_file(file, separator='=')
  file_abs_path = File.expand_path(file)
  if !File.exists? file_abs_path
    return [];
  end
  pods_ary = []
  skip_line_start_symbols = ["#""/"]
  File.foreach(file_abs_path) { |line|
      next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
      plugin = line.split(pattern=separator)
      if plugin.length == 2
        podname = plugin[0].strip()
        path = plugin[1].strip()
        podpath = File.expand_path("#{path}", file_abs_path)
        pods_ary.push({:name => podname, :path => podpath});
      else
        puts "Invalid plugin specification: #{line}"
      end
  }
  return pods_ary
end
 
target 'Runner' do
  use_frameworks!
  # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
  # referring to absolute paths on developers' machines.
  system('rm -rf .symlinks')
  system('mkdir -p .symlinks/plugins')
 
  # Flutter Pods
  generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
  if generated_xcode_build_settings.empty?
    puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
  end
  generated_xcode_build_settings.map { |p|
    if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
      symlink = File.join('.symlinks''flutter')
      File.symlink(File.dirname(p[:path]), symlink)
      pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
    end
  }
  pod 'SAMKeychain'
 
  # Plugin Pods
  plugin_pods = parse_KV_file('../.flutter-plugins')
  plugin_pods.map { |p|
    symlink = File.join('.symlinks''plugins', p[:name])
    File.symlink(p[:path], symlink)
    pod p[:name], :path => File.join(symlink, 'ios')
  }
end
 
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '4.2.1' # added this
    end
  end
end

 26.flutter: Another exception was thrown: setState() or markNeedsBuild() called during build.

我的解决方案是把setState稍微延迟一下子

Future.delayed(Duration(milliseconds: 200)).then((e) {
  setState(() {
    ...
  });
});

 27.iOS真机出现Could not launch engine with configuration

解决方案是 :    https://github.com/flutter/flutter/issues/21221

虽然感觉有点不对门,但是总之解决了就行.......

28.XXXXX is a SingleTickerProviderStateMixin but multiple tickers were created.

原因是多个地方调用setState请求重绘,但是state使用的是SingleTickerProviderStateMixin ,将其改成TickerProviderStateMixin即可。

 29.使用fluro管理路由时,在传输参数时出现传输特殊字符,会被自动截取.就像下面传输+12345过去,那边只能收到12345......

这个时候需要被传输的数据进行特殊处理,编码一下就可以

 30.

Error on line 52, column 4 of pubspec.yaml: Expected a key while parsing a block mapping.

 │ assets:
│ ^

 

这个问题就是一个智障问题了: 

assets前面多了个空格,去除就好....
31. Text的换行属性 :softWrap: true
在其他组件中,使用Text需要换行,其外面最好加一个Expanded

 

 32.想要在Column中使用ListView.

如果想要在Column中使用ListView.需要对ListView的外面包裹一层:Expanded
如:

复制代码
Column(
     children: <Widget>[
        Text('3456789'),
        Expanded(
            child: ListView(
                children: <Widget>[ ],
         ),
     ),    
  ]
)
复制代码

 33.返回 Future<bool>:

需要使用 Future.value(false); 如

复制代码
 /*
   * Android 物理键返回 
   */
  Future<bool> _showToast() {
    if (_lastPressedAt == null ||
        DateTime.now().difference(_lastPressedAt) > Duration(seconds: 1)) {
      //两次点击间隔超过1秒则重新计时
      _lastPressedAt = DateTime.now();
      Fluttertoast.showToast(
        msg: "连续双击退出APP",
        toastLength: Toast.LENGTH_LONG,
      );
      return Future.value(false);
    }
    return Future.value(true);
  }
复制代码

 34.设置Drawer的宽度.

直接在Drawer的外面包裹一层Container.然后设置Container的宽度即可.:


 

 35.使用Flutter自带的CircularProgressIndicator 绘制圆环进度时.出现一瞬间的错误UI.原因很小学知识.因为我的进度是两数相除所得.默认都是0.除数不能为0!!!!!!!!!!!! 

 

 36.网络请求有时放在 initState 太早了. 会发生异常:

如我的这个,需要先获取两个本地化的值,然后才能请求网络,但是常常太晚了.于是awiat 取值,网络请求. 不行!如警告所说放在 didChangeDependencies 里面.同时对所有需要等待的程序awiat即可.

 

 

 37.之前在上传TestFlight的时候,下载之后打开app发现黑屏了...

有时Xcode还输出: Failed to find snapshot: XXXX  Engline run configyation was inavalid.  Could not launch engine with configuration.

 

 

 

 

找了下,这样可以解决:

 

 38.Android添加启动页并全屏.

 39.AS之前取消了版本更新,现在需要更新下.但是检测不到版本.

如下所示,点击1处.删除其中的版本信息.然后点击2处即可.

 40. 手机只能竖屏.

 

 

1
2
3
4
5
import 'package:flutter/services.dart';
  
 // 强制只能竖屏
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

41. A类 想要调用B类的方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import 'package:flutter/material.dart';
 
void main() => runApp(MyApp());
 
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}
 
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
 
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('调用其他类的方法'),
      ),
      body: FlatButton(
        child: Text('调用其他类的方法'),
        onPressed: _btnAction,
      ),
    );
  }
 
  _btnAction() {
    Two two = Two();
    two.twoAction();
 
    Three three = Three();
    three.createState().threeAction();
  }
}
 
class Two extends StatelessWidget {
  twoAction() {
    print('twoActiontwoActiontwoAction');
  }
 
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}
 
class Three extends StatefulWidget {
  @override
  _ThreeState createState() => _ThreeState();
}
 
class _ThreeState extends State<Three> {
  threeAction() {
    print('threeActionthreeActionthreeActionthreeAction');
  }
 
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

  

42.进入一家新公司,拉取代码后模拟器好的.真机会出现: 'ios/Runner/Runner.entitlements' could not be opened. Verify the value of the CODE_SIGN_ENTITLEMETS build setting for target 'RUNNER' and build configuration "Debug" is correct and that the file exists on the disk.(in taget 'Runner')

 

 

 我的问题是没有打开推送通知的开关.

 

43.上传app store或者Test Flight时.一直不显示版本包,出现: TMS-90338: Non-public API usage -The app references non-public symbols in Frameworks/Flutter.framework/Flutter: _ptrace 的邮件信息.

 

 

 

解决方案:  https://github.com/flutter/flutter/issues/37850   
               https://blog.csdn.net/xudailong_blog/article/details/101268214
 44.android 的AS 出现 Add Configuration....
我出现这个问题是因为导入一个库,但是这个库是用不了,我再次去除时,AS就变这样了.....尴尬.搞了一下午.最后发现只需要修改一下版本就好了,

 解决方案如下:

 https://blog.csdn.net/qq_36488374/article/details/80563633

 

45.卸载cocoapods之后再重新安装,运行pod setup无效,但是pod --version可以看到版本.flutter doctor报cocoapods压根不存在.pod install让我pod setup.pod setup又无效.....恶心死了.....百度一下午没有...老大说用谷00歌.答案一下子就出来了===> https://github.com/CocoaPods/CocoaPods/issues/9184
马丹.百度真恶心.政策真恶心.

46.iOS启动报错:VM snapshot invalid and could not be inferred form settings等字样

 

 解决方案是修改Edit Scheme...为release. 参考如下链接

https://github.com/flutter/flutter/issues/24641

47.跳转界面传值出现 :

flutter: The following ArgumentError was thrown while handling a gesture:

flutter: Invalid argument(s): Illegal percent encoding in URI

 

 原因是传的值不能包含中文. 需要转一下码:  Uri.encodeComponent("汉字")

 

 48.flutter build ios 出现 Using 'ARCHS' setting to build architectures of target 'Pods-Runner':('')

 

 

 

 看图识字,修改一下 iOS目录下的Podfile文件.添加一行 platform :ios, '9.0'

 

 即可.

 49. android打包出现 Could not resolve com.tencent.mm.opensdk:wechat-sdk-android-without-mta:+.

 

 解决方案:翻 00墙00
恶心00的00墙.恶00心的土 00匪

50.使用了Flutter json_serializable这个插件运行flutter packages pub run build_runner build:出现pub finished with exit code 78.

 

解决办法:运行 flutter packages pub run build_runner build --delete-conflicting-outputs  即可.

51. iOS在上传App Store时,出现GeoJSON无效:您的路由App覆盖地区文件失效......

 

 

 

 

原因: 图片文件或者路径包含了中文字符.修改即可.

 

52. iOS 打包在Archive的时候出现 could not find an option named "track-widget-creation"

 

 

 解决办法:  在Archive之前先执行 

flutter build ios --release

 参考: https://github.com/flutter/flutter/issues/26279

 

 53. Android真机出现NoSuchMethodError: The method 'tabLabel' was called on null.Receiver null Tried calling: tabLabel().

如图

 

 或者出现:

 

 

 出现这个问题,我这边是因为代码里面一开始使用了国际化,配置了

 

supportedLocales: [
//此处
const Locale('zh', 'CH'),
const Locale('en', 'US'),
],

后来没用国际化了.这个代码我就懒得删除......就是这个玩意造成的.iOS可以,Android就不行.  删除这个就好了...恶心我半个小时

 

54. 最近换电脑,一样的代码,一样的开发环境,但是新电脑就是运行不起来。旧电脑键盘还废了。。。。草

出现 

Using `ARCHS` setting to build architectures of target `Pods-Sample`: (``) 

同时 pod install也也不行,原因一样。。

看来是pod的问题,于是升级到最新1.8.4 不行,降级1.8.3不行。还是必须降级到1.7.5 
55. Android报 A proglem occured configuring root project 'android'

 

 

 

搞了好久。最后发现需要翻696墙。。。。。恶心的土匪。建你 妈妈 的 墙

56.在对项目flutter clean出现‘FileSystemException: Delation ,path = 'build' (OS Error: Permission denied,rrror =13)’....

 

 

 解决办法:可以 sudo flutter clean一下。但是感觉不严谨。容易出事。

应该在选中根目录文件夹 右键 显示简介 共享与权限 找到自己的当前账户 点击锁 输入密码解开 点击应用到包含的项目。稍等一下即可。

 57.  在使用 

_pageController.animateToPage(widget.index,
duration: const Duration(milliseconds: 2), curve: Curves.ease);时报错:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
flutter: The following assertion was thrown building Builder:
flutter: ScrollController not attached to any scroll views.
flutter: 'package:flutter/src/widgets/scroll_controller.dart':
flutter: Failed assertion: line 110 pos 12: '_positions.isNotEmpty'
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:

 

 

 

 其实,只需要延时一下而已,需要先等待界面初始化好再滑动.

 

 58.出现  setState() called after dispose()

 

 顾名思义,在dispose()之后调用了setState().解决办法:

1
2
3
4
5
if (mounted) {
          setState(() {
..........
          });
}

  

 59.TextField 需要加个背景色.filled必须为true

 

 60.需要在initstate里面使用context.

比如:需要在initstate方法里面获取到屏幕的高来做一个动画的话,可以像这样:

复制代码
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _controller = new AnimationController(
          duration: const Duration(milliseconds: 300), vsync: this);
      _animation =
          new Tween(begin: 0.0, end: MediaQuery.of(context).size.height)
              .animate(_controller)
                ..addListener(() {
                  setState(() {});
                });
    });

  }
复制代码

关键点就是使用

 

1
2
WidgetsBinding.instance.addPostFrameCallback((_) {
        .....这里可以获取到context
1
});

  

61.使用Center的注意点:

使用Center会对包裹Center的组件发生类似Expanded 的作用.

62.model的判断

可以直接?判断是否为空,不为空才会取后面的值.比如:

 

 63.在最近几日,flutter build ios时,经常被墙.翻了墙也不行,换手机网络也不行.报错:

error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 60

 

 

 

 这个错误,当初在做iOS原生开发遇到过.都是翻下墙就好了.但是现在不行.只能换源了.还必须有两个源才行.一个默认自带的,一个天朝这边的....真是够了...

 如果这样还是不行.可以让终端也走代理设置. (或者Mac下载一个ITerm代替终端使用亦可)

 

 64.在使用fluwx分享时,因为分享有点慢,就加了个loading图,需要同时在微信回调和界面返回时,控制loading的显示与否.回调控制是好的,但是如果用户点击的是系统返回.就不行了.只能借助flutter官方的生命周期监听了.

 但是呢,只有在 AppLifecycleState.resumed 下才能修改state. 如果是其余状态修改的话,分享的剩余状态就会失败了....

 

这里的修改state最好是在外面加一层延时,延时之后再setState,保证万无一失. 

65.界面出现多次请求或者多次渲染情况.比如多次切换Tab,或者一个界面使用了其他封装的图片class.在上下滑动时,出现图片再次渲染现象.或者在写一个列表时,对其中的class小部件也做下保持状态,防止小部件为class的时候,上下滑动时,界面重置. 这个情况需要配置切换tab和混入其他类:AutomaticKeepAliveClientMixin.详见当初学习时写的项目.

 https://github.com/pheromone/flutter_shop
https://github.com/pheromone/flutter_video_audio_news

 66.showModalBottomSheet切圆角

https://blog.csdn.net/cpcpcp123/article/details/97660036

 67.点击空白缩回键盘.类似于原生的取消第一响应者功能.

https://segmentfault.com/a/1190000021314427

https://www.cnblogs.com/LiuPan2016/p/10347423.html

68.  点击其他按钮弹出键盘,调起第一响应者.

复制代码
// Initialise outside the build method
FocusNode nodeOne = FocusNode();
FocusNode nodeTwo = FocusNode();
// Do this inside the build method
TextField(
  focusNode: nodeOne,
),
TextField(
  focusNode: nodeTwo,
),
RaisedButton(
  onPressed: () {
    FocusScope.of(context).requestFocus(nodeTwo);
  },
  child: Text("Next Field"),
),
复制代码

https://www.jianshu.com/p/f6b994fdb9fb

69.  ios   Undefined symbols for architecture armv7:

https://www.jianshu.com/p/c37831cef020

 

70.最近,代码被搞丢了.于是重新拉取库,build的时候iOS出现: flutter unable to open file (in project "Runner") (in target 'Runner')
 

 

 解决办法: 

1.  cd 根目录

2.  flutter clean

3.  flutter create . 

4.重新打开Xcode.clean即可

https://github.com/flutter/flutter/issues/22886

71.最近,代码被搞丢了.于是重新拉取库,build的时候Android出现:SSL peer shut down incorrectly

https://www.jianshu.com/p/194b57cf7162

 

ps:恶心的某个组织.艹

72. 修改TextField的高度,以及无边框圆角

https://www.cnblogs.com/ChengYing-Freedom/p/10304959.html

73. TextField提示语hintText不居中

 

https://blog.csdn.net/ly410726/article/details/102698351

 74.textField设置圆形边框并且改变边框颜色,如果不修改会显示主题颜色

https://blog.csdn.net/xiaoqi307/article/details/95169874

 75.BottomNavigationBar设置4个BottomNavigationBarItem无效问题

需要加一个  type: BottomNavigationBarType.fixed,

 

 https://www.jianshu.com/p/363b66358de1

76. iOS打包出现: WARNING ITMS-90725:“SDK Version issue”.this app was build the iOS 12.4 SDK.Starting April 2020.all iOS apps submitted to the APP store must be build with the ios 13SDK or later,inclured in Xcode 11 or later

 

 

 

 

 使用AS运行出现 Flutter Device doesn't support wireless sync

 因为我的是Xcode10.3. flutter v1.9.1+hotfix.2 .我这边的方案是: channel master
如果报错说需要git pull, 那就 执行  git pull.之后会升级到最新的master版本.

 

 记得翻个墙墙.避开土匪干扰.  
之后通常就好了.flutter clean 之后再flutter build ios试试看三方库是否需要升级.如果需要它会提示.升级之后就可以正常运行真机和打包了

77.命令flutter build apk  出现  AndroidX incompatibilities may have caused this build to fai
https://www.zhulou.net/post/2366.html

 78.为了适配iOS13+升级了flutter,使用AS运行真机项目会一直卡在 Installing and launching...导致无法调试??????

百度几条,屁都没有,谷歌几条.试了也没啥用....模拟器是好的,真机不行....只能先模拟器测试了
a.https://github.com/flutter/flutter/issues/43570

 

 没用....

b.https://github.com/flutter/flutter/issues/46705
.

 

没用.

c.https://github.com/flutter/flutter/issues/37699
c.

 

 只能热重启,无法看到日志输出.....鸡肋..
  最终,只能升级到最新才行.....

79. flutter packages get 之后长时间没有反应(饭墙也一样,AS也一样.到底为何???)
可以在.bash_profile文件中添加

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

然后 

source ~/.bash_profile

然后打开饭墙,直接运行 flutter packages get 拉取

白天可以了.但是晚上还是会慢 

 

转自:程序猿--少停  link

posted @ 2020-04-01 14:44  久依  阅读(4104)  评论(0编辑  收藏  举报