Running Gradle task 'assembleDebug'...
需要修改安卓項目里的依賴Gradle文件, Gradle的Maven倉庫在國外, 需要使用阿里雲的鏡像地址替換一下
android/build.gradle 和 packages/flutter_tools/gradle/flutter.gradle都需要改一下
// google()
// jcenter()
// 添加國內的鏡像
maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
有FloatingActionButton
的頁面,跳轉二級頁面會出現黑屏的現象
There are multiple heroes that share the same tag within a subtree.
Flutter首頁里加了腳手架里的加號按鈕floatingActionButton
,頁面結構大致是這樣,從上往下依次是appBar,ListView,floatActionButton..,在listView的item里面的一個點擊回調的事件里做頁面跳轉,一跳轉就是黑屏,這個問題折騰了許久,主要花在了排查問題上,排查了路由設置問題和類名以及頁面結構等問題之后還是無果,最后拿控制台的一句話"There are multiple heroes that share the same tag within a subtree."粘貼到google上出來了一些結果,問題根源在於FloatingActionButton的一個屬性標識即heroTag
沒有設置,要手動設置一個標識唯一即可
Provide<MyCounter>(
builder: (context, child, val) {
int currentCount = Provide.value<MyCounter>(context).currentCount;
return Scaffold(
appBar: AppBar(
title: Text("首頁 $currentCount", style: TextStyle(color: Colors.white)),
flexibleSpace: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue[100], Colors.blue[300], Colors.blue],
begin: Alignment.topCenter,
end: Alignment.bottomCenter),
),
),
),
body: Container(
child: ListView.builder(
itemCount: dataList.length,
itemBuilder: (BuildContext context, int index) {
String name = dataList[index].name;
Function callBack = dataList[index].tapCallBack;
return Column(
children: <Widget>[
ListTile(
title: Text(name),
onTap: callBack,
),
Divider(),
],
);
},
)),
floatingActionButton: FloatingActionButton(
heroTag: "你大爺的", //就是這個玩意兒
child: Icon(Icons.add, color: Colors.white, size: 44),
backgroundColor: Colors.blueAccent,
onPressed: () {
Provide.value<MyCounter>(context).updateCount(currentCount);
},
),
);
},
);
參考博文
Flutter: There are multiple heroes that share the same tag within a subtree異常
flutter 跳轉報錯:There are multiple heroes that share the same tag within a subtree.
終端設置代理導致熱重載失敗或者是用不了
解決辦法:
在終端的~/.zshrc
或者~/.bash_profile
中查找如下設置代理的代碼,暫時先注釋掉,souce更新一下再看看是啥情況
export http_proxy=http://代理ip:端口
export https_proxy=http://代理ip:端口
重啟VSCode
和終端,再次flutter run
,驚喜出現了:
....
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h Repeat this help message.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
An Observatory debugger and profiler on iPhone 11 Pro Max is available at: http://127.0.0.1:52116/sXVB7ndU73U=/
Waiting for another flutter command to release the startup lock...
rm ./flutter/bin/cache/lockfile
舊項目編譯失敗
Error: Could not resolve the package 'characters' in 'package:characters/characters.dart'.
../../../../flutter/packages/flutter/lib/src/material/text_field.dart:9:8: Error: Not found: 'package:characters/characters.dart'
import 'package:characters/characters.dart';
^
../../../../flutter/packages/flutter/lib/widgets.dart:18:1: Error: Not found: 'package:characters/characters.dart'
export 'package:characters/characters.dart';
^
flutter pub cache repair 或者 flutter clean 然后 flutter run