我有一个出生日期格式的字段。
我尝试了一些代码,但它显示日期和时间,但我只想要日期。
有什么完美的方法吗?
变量
String initValue="Select your Birth Date";
bool isDateSelected= false;
DateTime birthDate; // instance of DateTime
String birthDateInString;
Run Code Online (Sandbox Code Playgroud)
这里是日期时间选择器的代码。
GestureDetector(
child: new Icon(Icons.calendar_today),
onTap: ()async{
final datePick= await showDatePicker(
context: context,
initialDate: new DateTime.now(),
firstDate: new DateTime(1900),
lastDate: new DateTime(2100)
);
if(datePick!=null && datePick!=birthDate){
setState(() {
birthDate=datePick;
isDateSelected=true;
birthDateInString = "${birthDate.month}/${birthDate.day}/${birthDate.year}";
});
}
}
)
Run Code Online (Sandbox Code Playgroud)
此小部件用于显示日期
new Text(isDateSelected ? "$birthDate":initValue),
Run Code Online (Sandbox Code Playgroud) 我正在尝试收集 onlysetState()模式和 BLoC 模式之间的差异点。
&刚刚收集到的一个区别点是:
1.)setState()方法始终与 一起使用Stateful Widget,但是 BLoC 模式可以与 Widget Stateless或 Stateful.
所以我的问题是,两者之间的主要区别是什么?哪个更好、更可靠?
我在文本字段中验证时遇到问题。如果我在文本字段中输入的所有值都是空白,那么当我按下提交按钮时,它应该抛出验证错误。我尝试用 isEmpty 解决但不起作用。
TextFormField textField(BuildContext context) {
return TextFormField(
maxLines: 10,
minLines: 6,
controller: _noteTextController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(screenAwareSize(3, 6, context)),
gapPadding: 0,
),
hintText: 'Enter Note'),
onSaved: (value) {
//store your value here
},
validator: (value) {
if (value.isEmpty) {
return 'Notes can\'t be empty';
} else {
return null;
}
});
}
Run Code Online (Sandbox Code Playgroud) 键盘在颤动中隐藏了我的底部工作表文本字段。我打开了文本字段的底部工作表,但是当开始输入一些文本时,键盘打开并隐藏文本字段底部工作表和“保存”按钮,因此无法看到我在文本字段中输入的内容。
见下图
我想要这个结果:
代码:
单击“+ 添加”按钮打开底部工作表。
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Form(
key: formKey,
child: Container(
padding: const EdgeInsets.all(8),
height: MediaQuery.of(context).size.height/4.5,
// color: Colors.red,
child: Column(
children: <Widget>[
Container(
padding: const EdgeInsets.all(10),
child: TextFormField(
controller: _noteTextController,
maxLines: 2,
minLines: 2,
decoration: InputDecoration(
hintText: "Add Note",
border: InputBorder.none
),
validator: (value){
if(value.trim().isEmpty){
return 'Notes can\'t be empty';
} else {
return null;
}
},
),
),
Container(
padding: const EdgeInsets.all(8),
width: MediaQuery.of(context).size.width,
// color: Colors.black,
alignment: Alignment.topRight,
child: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将国家/地区代码放在电话号码之前。我使用了country_pickers包,但我的代码出了问题,我的 TextField 的提示文本可见性消失了,它什么也没显示
这是我的小部件
Padding(
padding: const EdgeInsets.only(top: 5.0),
child: new Container(
padding: const EdgeInsets.only(left: 10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
border: Border.all(color: Colors.blue)
),
child: TextField(
keyboardType: TextInputType.phone,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Phone Number",
prefix: CountryPickerDropdown(
initialValue: 'in',
itemBuilder: _buildDropdownItem,
onValuePicked: (Country country) {
print("${country.name}");
},
),
),
onChanged: (value){
this.phoneNo=value;
},
),
),
),
Run Code Online (Sandbox Code Playgroud)
这是国家/地区代码的小部件方法
Widget _buildDropdownItem(Country country) => Container(
child: Row(
children: <Widget>[
CountryPickerUtils.getDefaultFlagImage(country),
SizedBox(
width: 8.0,
),
Text("+${country.phoneCode}(${country.isoCode})"),
],
),
);
Run Code Online (Sandbox Code Playgroud) 我要尝试从 firestore 数据库中获取图像并将其放入字符串类型列表并希望显示为滑块图像。但上述错误发生在屏幕上,但几毫秒后,错误消失,图像显示为滑块
已声明的全局变量:
List<String> getSliderImages=[];
Run Code Online (Sandbox Code Playgroud)
从 Firestore 获取图像的方法:
这个方法正在调用内部initState()方法
void getSliderImage(){
List<String> userId=[];
Firestore.instance.collection("Slider").getDocuments()
.then((QuerySnapshot snapshot) {
snapshot.documents.forEach((f){
setState(() {
userId.add(f.documentID);
});
});
for(int i=0;i<userId.length;i++){
setState(() {
print('snap.documentID_IF_userId :${userId[i]}');
Firestore.instance.collection('Slider').document(userId[i]).get().then((DocumentSnapshot document){
String image=document['Image'];
getSliderImages.add(image);
print('snap.documentID_IF_userId_IMAGE :$image');
print("getSliderImages:$getSliderImages");
});
});
}
}).catchError((onError){
print(onError);
setState(() {
Fluttertoast.showToast(msg: "$onError");
});
});
}
Run Code Online (Sandbox Code Playgroud)
滑块小部件,我想在那里显示图像:
这里我使用了carousel_pro插件作为 Slider
Container(
padding: const EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
//color: Colors.black
),
height: MediaQuery.of(context).size.height/5,
width: MediaQuery.of(context).size.height/2,
child: Carousel(
images: [
new NetworkImage(getSliderImages[0]),
new NetworkImage(getSliderImages[1]), …Run Code Online (Sandbox Code Playgroud) 如何动态设置 no ofPopupMenuItem到PopupMenuButtonwith 索引,如ListView.builder().
实际上,我用来FutureBuilder从 api 获取数据,作为响应,获取了 4 个项目,这意味着它提供了动态的项目数。并想以PopupMenuItem列表形式显示它们。PopupMenuButton但Like中没有 count 构造函数ListView.builder()。
代码:
FutureBuilder<CommonModel>(
future: futureListMaterialStatusCommonModel,
builder:(BuildContext context, AsyncSnapshot<CommonModel> snapshot ){
if(!snapshot.hasData){
return Text("loading...");
}
if(snapshot.hasError){
return Text(snapshot.error);
}
//I tried to get solution by loop before showing items but went wrong
for(int i ; i< snapshot.data.content.length; i++){
itemList.add(
PopupMenuItem(
value: snapshot.data.content[i].title,//919876543210,
child: Text(
snapshot.data.content[0].title,
style: TextStyle(
color: Colors.black, fontWeight: FontWeight.w700),
),
),
);
}
return PopupMenuButton<String>( …Run Code Online (Sandbox Code Playgroud) dart ×9
flutter ×9
bottom-sheet ×1
button ×1
country ×1
firebase ×1
phone-number ×1
popup ×1
seekbar ×1
textfield ×1
validation ×1