在 appBar 的 dropDownButton 中,我希望在更改專案時出現進度條。我為此撰寫了一個代碼,但進度條沒有出現。
class arayuzEkrani extends StatefulWidget {
const arayuzEkrani({Key? key}) : super(key: key);
@override
_arayuzEkraniState createState() => _arayuzEkraniState();
}
class _arayuzEkraniState extends State<arayuzEkrani> {
Map<String, String> countryFlags = {
"usa": "???? ?ngilizce",
"almanca": "???? Almanca",
};
List <subjectInfo> subjects = [subjectInfo("Selamla?ma", "assets/selamlasma.png"), subjectInfo("Hayvanlar", "assets/hayvanlar.png"), subjectInfo("Teknoloji", "assets/teknoloji.png"), subjectInfo("Meyve Sebze", "assets/meyvesebze.png"), subjectInfo("Meslekler", "assets/meslekler.png")];
// "Selamla?ma", "Hayvanlar", "Teknoloji", "Meyve ve Sebze", "Meslekler"
var defaultFlag = "???? ?ngilizce";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
leading: const Icon(
Icons.public,
color: Colors.black,
size: 27,
),
title: const Text(
"Kelime ??ren",
style: TextStyle(color: Colors.black),
),
elevation: 0,
actions: [
DropdownButton<String>(
items: countryFlags
.map((country, flag) {
return MapEntry(
country,
DropdownMenuItem<String>(
value: flag,
child: Text(flag, style: TextStyle(fontSize: 20),),
));
})
.values
.toList(),
value: defaultFlag,
onChanged: (String? country) {
setState(() {
defaultFlag = country!;
});
},
)
],
),
我希望 dropDownButton 中帶有更改選項的進度條出現。問題是什么?我該怎么做?
uj5u.com熱心網友回復:
嘗試這個,
bool isCountryChanged = false; // for update UI when country changed.
appBar: AppBar(
backgroundColor: Colors.transparent,
leading: const Icon(
Icons.public,
color: Colors.black,
size: 27,
),
title: const Text(
"Kelime ??ren",
style: TextStyle(color: Colors.black),
),
elevation: 0,
actions: [
isCountryChanged == false ?
DropdownButton<String>(
items: countryFlags
.map((country, flag) {
return MapEntry(
country,
DropdownMenuItem<String>(
value: flag,
child: Text(flag, style: TextStyle(fontSize: 20),),
));
})
.values
.toList(),
value: defaultFlag,
onChanged: (String? country) {
setState(() {
defaultFlag = country!;
isCountryChanged = true;
// display circular indicator for 1 second.
Future.delayed(const Duration(milliseconds: 1000), () async {
isCountryChanged = false;
});
});
},
) : CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.blue),
strokeWidth: 5,
);
],
),
uj5u.com熱心網友回復:
除非您看不到任何更改,否則必須使用回圈進度指示器。
uj5u.com熱心網友回復:
您可以創建一個持續時間型別的變數,然后創建一個函式,該函式回傳一個未來構建器,該構建器將等待持續時間完成,然后顯示國家,但同時將顯示一個圓形指示器
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/431583.html
