我遇到了一個錯誤。它說,
一個'字串'型別的值不能被分配給一個'字串'型別的變數。 'String'的變數。試著改變變數的型別,或者將右邊的型別轉換為 右手型別為'String'。
在這個問題上遇到了錯誤,。 這段代碼在下面的完整代碼中
onChanged: (val) => setState(
() => _applyleavevalueChanged = val)。
驗證器。(val) {
設定狀態(
() => _applyleavevalueToValidate = val)。
return null。
},
onSaved: (val) => setState(
() => _applyleavevalueSaved = val)。
我遇到了一個關于val的錯誤...。它說,
一個'String?'型別的值不能被分配給一個'String'型別的變數。 'String'的變數。試著改變變數的型別,或者將右邊的型別轉換為 右手型別為'String'。
這是我的全部源代碼.....
檔案:leaveapply.dart
import 'package:date_time_picker/date_time_picker.dart'/span>。
import 'package:dropdown_search/dropdown_search.dart'。
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import './LeaveApply/BouncingButton.dart'。
import './LeaveApply/leave_history.dart';
import 'LeaveApply/LeaveHistoryCard.dart';
import 'LeaveApply/datepicker.dart';
void main() {
runApp(MaterialApp(
debugShowCheckedModeBanner。false,
首頁。LeaveApply(),
標題。'Leave Apply',
));
}
class LeaveApply extends StatefulWidget{
@override
_LeaveApplyState createState() => _LeaveApplyState()。
}
class _LeaveApplyState extends State< LeaveApply>
with SingleTickerProviderStateMixin {
late Animation animation, delayedAnimation, muchDelayedAnimation, LeftCurve;
late AnimationController animationController;
final searchFieldController = TextEditingController();
后期 TextEditingController _applyleavecontroller;
String _applyleavevalueChanged = ''/span>;
String _applyleavevalueToValidate = ''/span>;
String _applyleavevalueSaved = ''/span>;
late TextEditingController _fromcontroller;
String _fromvalueChanged = ''/span>;
String _fromvalueToValidate = '';
String _fromvalueSaved = '';
late TextEditingController _tocontroller;
String _tovalueChanged = ''/span>;
String _tovalueToValidate = '';
String _tovalueSaved = '';
@override
void initState() {
// ignore: todo
//TODO: implement initState。
super.initState()。
//SystemChrome.setEnabledSystemUIOverlays([]);
_applyleavecontroller =
TextEditingController(text: DateTime.now().toString())。
_fromcontroller = TextEditingController(text: DateTime.now().toString())。
_tocontroller = TextEditingController(text: DateTime.now().toString())。)
animationController =
AnimationController(duration: Duration(seconds: 3), vsync: this)。)
animation = Tween(begin: -1.0, end: 0.0).animate(CurvedAnimation(
parent: animationController, curve: Curves.fastOutSlowIn))。)
delayedAnimation = Tween( begin: 1.0, end: 0.0).animate(CurvedAnimation(
parent: animationController,
曲線。Interval(0.2, 0.5, curve: Curves.fastOutSlowIn))。
muchDelayedAnimation = Tween(begin: -1.0, end: 0.0).animate(CurvedAnimation(
parent: animationController,
曲線。Interval(0.3, 0.5, curve: Curves.fastOutSlowIn))。
}
@override
void dispose() {
// ignore: todo
//TODO:實作處置。
animationController.dispose()。
super.dispose()。
}
final GlobalKey<FormState> _formkey = new GlobalKey<FormState>()。
@override
Widget build(BuildContext context) {
animationController.forward()。
final double width = MediaQuery.of(text).size.width;
final double height = MediaQuery.of(context).size.height;
final GlobalKey<ScaffoldState> _scaffoldKey =
new GlobalKey<ScaffoldState>()。
return AnimatedBuilder(
animation: animationController,
builder: (BuildContext context, Widget? child) {
final GlobalKey<ScaffoldState> _scaffoldKey =
new GlobalKey<ScaffoldState>()。
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
backgroundColor: Colors.white,
標題。文本(
'Apply Leave'。
風格。TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
領導。new IconButton(
圖示。new Icon(
Icons.arrow_back_ios,
color: Colors.black87,
大小。18.0。
),
onPressed: () => Navigator.of(context).pop()。
),
centerTitle: true。
高度。1.0。
),
body: 表格(
鍵。_formkey,
child: SingleChildScrollView(
child: padding(
padding: const EdgeInsets.symmetric(
horizontal: 15.0,
),
孩子。Column(
crossAxisAlignment: CrossAxisAlignment.start,
兒童。[
分割器(
color: Colors.black.withOpacity(0.5)。
高度。1,
),
SizedBox(
height: height * 0.05,
),
變換(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。文本(
"申請休假日期"。
風格。TextStyle(
fontWeight: FontWeight.bold,
字體大小。15,
),
),
),
填充(
padding: EdgeInsets.only(
頂部。13,
),
孩子。容器(
// height: height * 0.06,.
padding: EdgeInsets.only(
左邊。10,
),
width: double.infinity,
裝飾。BoxDecoration(
邊界。border.all(color: Colors.black),
borderRadius: borderRadius.round(5)。
),
孩子。行(
兒童。[
變換(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。容器(
width: width * 0.75,
孩子。DateTimePicker(
型別。DateTimePickerType.date,
dateMask: 'dd/MM/yyyy'。
控制器。_applyleavecontroller,
//initialValue。_initialValue,
firstDate。DateTime(2000)。
最后日期。DateTime(2100)。
calendarTitle。"休假日期"。
確認文本。"確認"。
enableSuggestions: true。
/locale: Locale('en', 'US'),
onChanged: (val) => setState(
() => _applyleavevalueChanged = val)。
驗證器。(val) {
設定狀態(
() => _applyleavevalueToValidate = val)。
return null。
},
onSaved: (val) => setState(
() => _applyleavevalueSaved = val) 。
),
),
),
變換(
變換。Matrix4.translationValues(
delayedAnimation.value * width, 0, 0)。)
孩子。圖示(
Icons.calendar_today,
color: Colors.black,
),
),
],
),
),
),
SizedBox(
height: height * 0.03,
),
變形(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。文本(
"選擇離開型別"。
風格。TextStyle(
fontWeight: FontWeight.w700,
字體大小。14,
),
),
),
SizedBox(
height: height * 0.02,
),
變形(
變換。Matrix4.translationValues(
delayedAnimation.value * width, 0, 0)。)
孩子。DropdownSearch<String>(
驗證器。(v) => v == null ? "required field" : null,
提示: "請選擇休假型別"。
模式。Mode.MENU,
showSelectedItems: true。
專案。[
"醫療",
"家庭"。
"Sick",
'功能'。
'其他'。
],
showClearButton。true。
onChanged: print。
),
),
SizedBox(
height: height * 0.05,
),
變形(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。文本(
"休假日期"。
風格。TextStyle(
fontWeight: FontWeight.bold,
字體大小。15,
),
),
),
填充(
padding: EdgeInsets.only(
頂部。13,
),
孩子。容器(
// height: height * 0.06,.
padding: EdgeInsets.only(
左邊。10,
),
width: double.infinity,
裝飾。BoxDecoration(
color: Colors.white38,
borderRadius: borderRadius.round(5)。
boxShadow: [
BoxShadow(
偏移。Offset(0, 1) 。
color: Colors.black12,
)
]),
孩子。行(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
兒童。[
變換(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。圖示(
Icons.calendar_today,
color: Colors.black,
),
),
變換(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。padding(
padding: const EdgeInsets.all(6.0)。
孩子。容器(
padding: const EdgeInsets.only(left: 4.0) 。
寬度:寬度*0.28。
裝飾。BoxDecoration(
color: Colors.white38,
boxShadow: [
BoxShadow(
offset: Offset(0, 1) 。
blurRadius: 2。
color: Colors.black26,
)
]),
孩子。CustomDatePicker(
控制器。_fromcontroller,
標題。"From"。
onchanged: (val) =>
setState(() => _fromvalueChanged = val)。
驗證器。(val) {
設定狀態()
() => _fromvalueToValidate = val)。
return null。
},
保存。(val) =>
setState(() => _fromvalueSaved = val)。
),
),
),
),
變換(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。圖示(
Icons.arrow_forward,
color: Colors.black,
),
),
變換(
變換。Matrix4.translationValues(
delayedAnimation.value * width, 0, 0)。)
孩子。Padding(
padding: const EdgeInsets.all(6.0)。
孩子。容器(
padding: const EdgeInsets.only(left: 4.0) 。
寬度:寬度*0.28。
裝飾。BoxDecoration(
color: Colors.white38,
boxShadow: [
BoxShadow(
offset: Offset(0, 1) 。
blurRadius: 2。
color: Colors.black26,
)
],
),
孩子。CustomDatePicker(
控制器。_tocontroller,
標題。"To"。
onchanged: (val) => setState(() {
_tovalueChanged = val;
print(val)。
}),
驗證器。(val) {
setState(() => _tovalueToValidate = val)。
return null。
},
保存。(val) =>
setState(() => _tovalueSaved = val)。
),
),
),
),
],
),
),
),
SizedBox(
height: height * 0.05,
),
變形(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。文本(
"申請休假日期"。
風格。TextStyle(
fontWeight: FontWeight.bold,
字體大小。15,
),
),
),
變形(
變換。Matrix4.translationValues(
delayedAnimation.value * width, 0, 0)。)
孩子。Padding(
padding: EdgeInsets.only(
頂部。13,
),
孩子。容器(
// height: height * 0.06,.
高度:高度*0.25。
width: double.無窮大。
裝飾。BoxDecoration(
邊界。border.all(color: Colors.black),
borderRadius: borderRadius.round(5)。
),
孩子。TextFormField(
//autofocus: true,。
minLines: 1。
maxLines: 10,
鍵盤型別。TextInputType.multiline,
裝飾。InputDecoration()
suffixIcon: searchFieldController.text.isNotEmpty
? IconButton(
圖示。Icon(Icons.clear),
onPressed: () => WidgetsBinding.instance
?.addPostFrameCallback((_) =>
searchFieldController.clear()))
: null。
邊界。InputBorder.none。
contentPadding: EdgeInsets.all(7)。
),
),
),
),
),
SizedBox(
height: height * 0.05,
),
變形(
變換。Matrix4.translationValues(
muchDelayedAnimation.value * width, 0, 0)。)
孩子。文本(
"附加檔案"。
風格。TextStyle(
fontWeight: FontWeight.bold,
字體大小。15,
),
),
),
變形(
變換。Matrix4.translationValues(
delayedAnimation.value * width, 0, 0)。)
孩子。Padding(
padding: const EdgeInsets.all(8.0)。
孩子。InkWell()
onTap: () async {},
孩子。文本(
"Click
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/329165.html
標籤:
