當我點擊地址 textformField 然后打開一個警報對話框,在這個警報對話框中,我有Dropdown,當我選擇任何Dropdown專案時,當時不顯示資料,當我重繪 頁面時,我的資料顯示在Dropdown上,請幫助我解決這個問題。
當我點擊地址textformField,然后打開一個警報對話框,在這個警報對話框中,我有Dropdown,當我選擇任何Dropdown專案,然后該時間不顯示資料,當我重繪 頁面,然后我的資料顯示在Dropdown上,顯示如何修復它,請幫助我。
這是我的代碼
import 'dart:convert'/span>;
import 'dart:io';
import 'package:firebase_auth/firebase_auth.dart'。
import 'package:flutter/cupertino.dart'。
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:http_interceptor/http/intercepted_client.dart';
import 'package:image_picker/image_picker.dart'。
import 'package:multi_image_picker2/multi_image_picker2.dart';
import 'package:readmore/readmore.dart'。
import 'package:http/http.dart' as http;
class ViewEditProfile extends StatefulWidget{
const ViewEditProfile({Key? key}) : super(key: key);
@override
_ViewEditProfileState createState() => _ViewEditProfileState()。
}
class _ViewEditProfileState extends State< ViewEditProfile> {
var _fullNameController = TextEditingController();
var _emailController = TextEditingController();
var _dobController = TextEditingController();
var _genderController = TextEditingController();
var _addressController = TextEditingController();
var _adharController = TextEditingController();
var _panController = TextEditingController();
var userPhoneNumber;
List? stateList = [];
List? districtList = [] 。
List? tehsilList = [];
List? villageList = [];
String? _selectedState;
String? _selectedDistrict;
String? _selectedTehsil;
String? _selectedVillage;
資料庫服務 db = 資料庫服務()。
@override
void initState() {
// TODO: implement initState
super.initState()。
//_loadSharedPrefs();
getGeoPointsDetailsUsingType()。
// genderFunct(); getGeoPointsDetailsUsingType()
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppbarNoSearch()。
body: SingleChildScrollView(
孩子。容器()
child: 列(
children: [
容器(
color: mPrimaryColor,
高度。媒體查詢
.of(context)
.大小
.高度/ 23。
寬度:媒體查詢
.of(context)
.尺寸
.寬度。
兒童。行(
子女。[
SizedBox(
width: 15,
),
InkWell(
onTap: () {
Navigator.pop(context);
},
child: 容器(
高度。媒體查詢
.of(context)
.尺寸
.高度/ 23。
寬度:30。
孩子。圖示(
Icons.arrow_back_ios_rounded,
大小。20,
color: whiteetext,
),
),
),
展開(
孩子。文本(
"VIEW EDIT PROFILE".tr(),
style: headingWhite(),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 40,
)
],
),
),
容器(
高度。媒體查詢
.of(context)
.尺寸
.高度/3.9。
寬度: MediaQuery
.of(context)
.尺寸
.寬度。
//寬度:110,。
//高度: 110,。
裝飾。BoxDecoration(boxShadow: [
BoxShadow()
color: gray,
偏移量。const Offset(
0,
5.0,
),
blurRadius: 5.0。
spreadRadius: 0,
), //BoxShadow(盒影)。
BoxShadow(
color: Colors.white,
偏移量。const Offset(0.0, 0.0) 。
blurRadius: 0.0。
spreadRadius: 0.0,
), //BoxShadow.
]),
孩子。列(
children: [
容器(
padding: EdgeInsets.only(top: 7, right: 15)。)
孩子。GestureDetector()
onTap: () {
isEnableFun(context);
},
child: 容器(
高度。24。
child: Align(
對齊。Alignment.topRight,
child: isEnable
? 文本(
'UPDATE'。
style: cardTitleGreen(),
)
: 文本(
'EDIT',
style: cardTitleGreen(),
),
),
),
),
),
行(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
兒童。[
容器(
padding: EdgeInsets.all(2) 。
寬度:120。
高度。120。
裝飾。BoxDecoration(
邊界。
border.all(color: mPrimaryColor, width: 1.0)。
borderRadius: borderRadius.round(60)。
),
child: isEnable == false ?
? 容器(
margin: EdgeInsets.all(1)。
裝飾。BoxDecoration(
borderRadius: borderRadius.round(60)。
影像。裝飾影像(
影像。網路影像(
"https://www.aiyd.org/wp-content/uploads/2016/09/no-image-icon-hi-1.png")。)
適合。BoxFit.cover))。
)
: 堆疊(
兒童。[
容器(
margin: EdgeInsets.all(1)。
裝飾。BoxDecoration(
borderRadius:
borderRadius.round(60)。
影像。裝飾影像(
影像。網路影像(
"https://www.aiyd.org/wp-content/uploads/2016/09/no-image-icon-hi-1.png")。)
適合。BoxFit.cover))。
),
定位(
頂部。0,
右邊。0,
孩子。InkWell()
onTap: () {
// shopLogoLoadAssets();
getImage()。
},
孩子。容器(
高度。40。
寬度: 40,
裝飾。BoxDecoration(
形狀。BoxShape.circle,
邊界。border.all(
width: 4, color: Colors.white)。)
color: mPrimaryColor,
),
孩子。圖示(
Icons.edit,
color: Colors.white,
),
),
),
),
],
),
),
SizedBox(
width: 25,
),
列(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center。
兒童。[
//星級地址部分。
填充(
padding: const EdgeInsets.only(
top: 14, left: 23, right: 23)。)
孩子。主題(
資料。ThemeData(
disabledColor: cardTextbgYellow,
),
孩子。TextFormField(
readOnly: true。
控制器。_addressController,
minLines: 2,
maxLines: 3,
鍵盤型別。TextInputType.multiline,
cursorColor: mPrimaryColor,
風格。TextStyle(color: mPrimaryColor)。
enabled: isEnable,
裝飾。InputDecoration(
prefixIconConstraints: BoxConstraints(
minWidth: 23,
),
prefixIcon: Padding(
padding: const EdgeInsets.only(
右邊。17,
),
孩子。Icon(
Icons.location_on_outlined,
color: mPrimaryColor,
),
),
hintText。"您的地址"。
hintStyle: cardTitleGreen(),
enabledBorder: UnderlineInputBorder(
borderSide:
borderSide(color: cardTextbg.withOpacity(0.5))。
),
focusedBorder: underlineInputBorder(
borderSide:
borderSide(color: cardTextbg.withOpacity(0.5))。
),
),
onTap: () {
setState(() {
showAddressDialog();
});
},
),
),
),
//end address partpan part。
SizedBox(
高度。20,
),
isEnable
? CustomButton(
文本。"SAVE".tr()。
textColor: Colors.white,
gradient: buttongradient,
圖示。Icons.arrow_forward_ios_outlined,
iconColor: Colors.white,
onPressed: () {},
)
: 容器()。
SizedBox(
高度。20。
),
],
)
],),
] ),),]),)
)
,
);
}
getGeoPointsDetailsUsingType() async {
db.getGeoPointDetailsByType("State").then((onValue) =>
{
setState(() {
stateList = onValue;
print("line 1")。
print("object::: " stateList!.length.toString())。
print("line 2") 。
})
});
}
getGeoPointsDetailsUsingId(String id, String type) async {
db.getGeoPointDetailsById(id).then((onValue) =>
{
print(type)。
setState(() {
print("id:: " id)。
if (type == "District"/span>) {
districtList = onValue;
print("districtList:: "/span> districtList.toString())。
} else if (type == "Tehsil"/span>) {
tehsilList = onValue;
} else if (type == "VillagePanchayat") {
villageList = onValue。
}
})
});
}
showAddressDialog() {
showDialog()
barrierDismissible: false。
背景關系: 背景關系。
builder: (context) =>
AlertDialog(
insetPadding: EdgeInsets.symmetric(horizontal: 10)。
可滾動。true。
行動。[
行(
mainAxisAlignment: MainAxisAlignment.center,
兒童。[
CustomButton2(
文本。"OK"。
onPressed: () {
Navigator.of(context).pop()。
},
gradient: buttongradient,
)
],
)
],
內容。容器(
寬度:媒體查詢
.of(context)
.尺寸
.寬度
兒童。列(
子女。[
行(
children: [
擴展的(
孩子。容器(
高度。30。
padding:
EdgeInsets.only(top: 0, left: 4, bottom: 0)。)
裝飾。BoxDecoration(
borderRadius: borderRadius.only(
topLeft: Radius.circular(8)。
bottomLeft: Radius.circular(8))。
邊界。border.all(
color: mPrimaryColorLight, width: 0.5) )。
孩子。DropdownButtonHideUnderline(
孩子。DropdownButton<String>(
focusColor: Colors.red,
提示:文本(
"State".tr(),
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值。_selectedState,
isExpanded: true。
提升。2,
圖示。圖示(
//增加這個。
Icons.arrow_drop_down, //>添加這個。
color: mPrimaryColorLight, //Add this0 ?
? List.generation(
stateList!.length,
(index) =>
DropdownMenuItem<String>(
值。
"${stateList![index]['referenceId']}。
孩子。new Text(
stateList! [index]['name']。
風格。文本風格(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
),
)
: ["Select State"].map((選項) {
return DropdownMenuItem(
孩子。文本(
"$option"。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值:選項。
);
}).toList()。
onChanged: (String? val) {
setState(() {
_selectedState = val;
print(_selectedState)。
if (stateList!.length > 0) {
getGeoPointsDetailsUsingId(
_selectedState!, "District")。)
}
});
},
),
),
),
),
擴展的(
孩子。容器(
高度。30。
padding:
EdgeInsets.only(top: 0, left: 4, bottom: 0)。)
裝飾。BoxDecoration(
邊界。border.all(
color: mPrimaryColorLight, width: 0.5) )。
孩子。DropdownButtonHideUnderline(
孩子。DropdownButton<String>(
focusColor: Colors.red,
提示:文本(
"區".tr()。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值。_selectedDistrict,
圖示。Icon(
//添加這個。
Icons.arrow_drop_down, //>添加這個。
color: mPrimaryColorLight, //Add thistrue。
提升。2,
items: districtList!.length > 0; ?
? List.generation(
districtList!.length,
(index) =>
DropdownMenuItem<String>(
值。
"${districtList![index]['referenceId']}。
孩子。new Text(
districtList? [index]['name']。
風格。TextStyle(
字體大小。13,
fontWeight:
FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
))
: ["選擇區"].map((option) {
return DropdownMenuItem(
孩子。文本(
"$option"。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值:選項。
);
}).toList()。
onChanged: (String? val) {
setState(() {
_selectedDistrict = val;
if (districtList!.length > 0) {
getGeoPointsDetailsUsingId(
_selectedDistrict!, "Tehsil")。)
}
});
},
),
),
),
),
擴展的(
孩子。容器(
高度。30。
padding:
EdgeInsets.only(top: 0, left: 4, bottom: 0)。)
裝飾。BoxDecoration(
邊界。border.all(
color: mPrimaryColorLight, width: 0.5) )。
孩子。DropdownButtonHideUnderline(
孩子。DropdownButton<String>(
focusColor: Colors.red,
提示:文本(
"Tehsil".tr()。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值。_selectedTehsil,
isExpanded: true。
海拔高度。2,
圖示。圖示(
//增加這個。
Icons.arrow_drop_down, //>添加這個。
color: mPrimaryColorLight, //Add this0
?
? List.generation(
tehsilList!.length,
(index) =>
DropdownMenuItem<String>(
值。
"${tehsilList![index]['referenceId']}。
孩子。new Text(
tehsilList! [index]['name']。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
)))
: ["Select Tehsil"].map((option) {
return DropdownMenuItem(
孩子。文本(
"$option"。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值:選項。
);
}).toList()。
onChanged: (String? val) {
setState(() {
_selectedTehsil = val;
if (tehsilList! .length > 0) {
getGeoPointsDetailsUsingId(
_selectedTehsil!, "VillagePanchayat")。)
}
});
},
),
),
),
),
擴展的(
孩子。容器(
高度。30。
padding:
EdgeInsets.only(top: 0, left: 4, bottom: 0)。)
裝飾。BoxDecoration(
borderRadius: borderRadius.only(
topRight: Radius.round(8)。
右下角。Radius.circular(8) )。
邊界。border.all(
color: mPrimaryColorLight, width: 0.5) )。
孩子。DropdownButtonHideUnderline(
孩子。DropdownButton<String>(
focusColor: Colors.red,
提示:文本(
"Village".tr(),
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值。_selectedVillage,
isExpanded: true。
海拔高度。2,
圖示。圖示(
//增加這個。
Icons.arrow_drop_down, //>添加這個。
color: mPrimaryColorLight, //Add this0 ?
? List.generation(
villageList!.length,
(index) =>
DropdownMenuItem<String>(
值。
"${villageList![index]['referenceId']}。
孩子。new Text(
villageList! [index]['name']。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
)))
: ["選擇村莊"].map((option) {
return DropdownMenuItem(
孩子。文本(
"$option"。
風格。TextStyle(
字體大小。13,
fontWeight: FontWeight.w500)。)
溢位。TextOverflow.ellipsis,
),
值:選項。
);
}).toList()。
onChanged: (String? val) {
setState(() {
_selectedVillage = val;
//getGeoPointsDetailsUsingId()
// _selectedVillage!
});
},
),
),
),
),
],
),
大小盒(
高度。5,
),
],
),
),
));
}
}
uj5u.com熱心網友回復:
嘗試用StatefulBuilder來包裝你的對話框
StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
//你的AlertDialog。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/332597.html
標籤:

