DART EXCEPTION HANDLING


PARSING   Change string value to double

void main(){
String myString = 'abc';

double myStringAsdouble = double.parse(myString);

print(myStringAsdouble + 56);
}     


Used example in a program how to use try and catch 

Catch takes the error and print in flutter terminal as written in code 

@override
Widget build(BuildContext context) {
String myString = "abc";
double margin;
try {
margin = double.parse(myString);
} catch (e) {
print(e);
margin = 30; // use this or
}

return Scaffold(
body: Container(
margin: EdgeInsets.all(margin ?? 30), // or use this
color: Colors.grey,
),
);
}

when margin takes value as 'abc' but it cant be converted into double so app return error message like below so we also give new margin value so that instead of that ('abc'), new value is used in a container 


DART NULL AWARE OPERATOR


As above we use margin ?? 30










                                                

Comments