flutter 3.0 upgrade 후 수정 사항들1

 dart list  선언 부분

The name 'FlatButton' isn't a class.

**Old Widget        change to    New Widget      
FlatButton   =>      TextButton      
RaisedButton =>      ElevatedButton  
OutlineButton =>    OutlinedButton**
에러메세지
The operator '[]' isn't defined for the type 'Object'.
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data?['obj'] == null) {
_naviButtonText = '등록';
} else {
_naviButtonText = '확인';
Map temp = snapshot.data['obj'];
temp.forEach((key, value) {
_regiInfo[key] = value;
});
builder: (context, snapshot) {
if (snapshot.hasData) {
if ((snapshot.data as Map)['obj'] == null) {

* 삼항식 변경
기존 
boolname ? aaaa:bbbb;
변경
boolname==true ? aaaa:bbbb;

The return type 'WebView' isn't a 'Widget', as required by the closure's context. Open documentation
Undefined name 'JavascriptMode'.  Try correcting the name to one that is defined, or defining the name. Open documentation

삼항연산자

   int value1 = 5;
   bool value2 = false;
 
    value2 = value ? 100 : 200;  

?는 자바에서도 볼 수 있는 삼항연산자입니다.

? 앞의 수식이 true면 :의 앞쪽을 반환하고 false면 :의 뒤쪽을 반환합니다.

플러터에서 굉장히 자주 사용하게 되는데, widget내에서는 if문을 사용하지 못하기 때문입니다.

 

isSignIn
 	? RaisedButton(
       child: Text('SingUP')
       onPressed:(){}
       )
	: SizedBox(),

예시처럼 조건에 맞게 widget이 랜더되야하는 경우에는 삼항연산자를 사용해야합니다.

또, 크기나 기타 위젯의 속성들을 조건에 맞추는 경우도 마찬가지입니다.

그리고 삼항연산자는 반드시 true와 false 두가지 반환값이 필요한데, 아무 위젯도 반환하고 싶지 않을 경우에는

SizedBox를 반환하는 것이 일반적입니다.

정리하자면 if문은 widget에서 사용할 수 없으니 삼항연산자를 사용해야합니다.


The property 'length' can't be unconditionally accessed because the receiver can be 'null'.
수정전 ==> AsyncSnapshot 추가 한다
builder: (context, snapshot) {
if (snapshot.hasData) {
bizList = snapshot.data as List?;
List<Item> bizListItems = <Item>[];
// var d_length = snapshot.data!.length as int ;

for (int i = 0; i < snapshot.data.length; i++) {
Map? map = snapshot.data[i];
String _temp = map['biz_reg_no'].toString();
bizListItems.add(new Item(
map['biz_nm'],
_temp,
null,
));
   }
builder: (context, AsyncSnapshot  snapshot) {
if (snapshot.hasData) {
bizList = snapshot.data as List?;
List<Item> bizListItems = <Item>[];
// var d_length = snapshot.data!.length as int ;

for (int i = 0; i < snapshot.data.length; i++) {
Map? map = snapshot.
data[i];
String _temp = map['biz_reg_no'].toString();
bizListItems.add(new Item(
map[
'biz_nm'],
_temp,
null,
));
}
new List<SalesInfo>()
==>   <SalesInfo>[]

salesInfo?.add(new SalesInfo.fromJson(v));
null 가능 하게 선언 ?
builder: (BuildContext context, String val, Widget widget) {
return RichText(
textAlign: TextAlign.left,
text: TextSpan(
children: [
TextSpan(
// text: cust.cust_nm==''||cust.cust_nm == null?'사장':cust.cust_nm,
text: _cust_nm,
style: TextStyle(
fontSize: 14,
fontFamily: "NanumGothic",
fontWeight: FontWeight.w700,
color: Color(0xff999999))),
TextSpan(
text: '님의 마이페이지',
style: TextStyle(
fontSize: 14,
fontFamily: "NanumGothic",
fontWeight: FontWeight.w700,
color: Colors.black)),
],
    ),


builder: (BuildContext? context, String? val, Widget? widget) {
return RichText(
textAlign: TextAlign.left,
text: TextSpan(
children: [
TextSpan(
// text: cust.cust_nm==''||cust.cust_nm == null?'사장':cust.cust_nm,
text: _cust_nm,
style: TextStyle(
fontSize: 14,
fontFamily: "NanumGothic",
fontWeight: FontWeight.w700,
color: Color(0xff999999))),
TextSpan(
text: '님의 마이페이지',
style: TextStyle(
fontSize: 14,
fontFamily: "NanumGothic",
fontWeight: FontWeight.w700,
color: Colors.black)),
      ],
변수 선언 부분에 nullable 속성 선언해 주면 된다 


댓글

이 블로그의 인기 게시물

자바 string 비교 할때 equlas 를 사용하자

jqgrid 에서 export execl 붙이기

flutter webview scroll 안되는 경우 gestureRecognizers: gestureRecognizers, 추가 해서 되었다