Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Error handling in Flutter
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Enzo Lizama Paredes
May 22, 2020
Programming
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Error handling in Flutter
Enzo Lizama Paredes
May 22, 2020
More Decks by Enzo Lizama Paredes
See All by Enzo Lizama Paredes
BDD in Flutter
enzoftware
0
94
Adding Flutter to an existing Android/iOS app
enzoftware
0
170
Flutter flavors
enzoftware
0
83
Flutter CI/CD with Fastlane
enzoftware
0
88
Flutter Animations
enzoftware
0
64
Productivity tools 4 developers
enzoftware
0
53
OpenCV + Android
enzoftware
1
71
Anko Superpowers
enzoftware
0
80
Mobile Vision API + Android
enzoftware
0
71
Other Decks in Programming
See All in Programming
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
540
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
340
5分で問診!Composer セキュリティ健康診断
codmoninc
0
560
霧の中の代数的エフェクト
funnyycat
1
410
AIが無かった頃の素敵な出会いの話
codmoninc
1
190
1年で人数1.5倍、PR数5.5倍増。 品質とアウトカムはどうなったか、 何が効いたか
ike002jp
0
140
関数型プログラミングのメリットって何だろう?
wanko_it
0
190
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
520
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.2k
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
390
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
490
PHP初心者セッション2026 〜生成AIでは見えない裏側を知る:今だからLAMPを通して仕組みを学ぶ〜
kashioka
0
630
Featured
See All Featured
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
660
Thoughts on Productivity
jonyablonski
76
5.3k
Mobile First: as difficult as doing things right
swwweet
225
10k
WCS-LA-2024
lcolladotor
0
740
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
730
sira's awesome portfolio website redesign presentation
elsirapls
0
310
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
490
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
320
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
Transcript
Enzo Lizama Error handling in Flutter @enzoftware
KotlinConf 2019: Error Handling Strategies for Kotlin Programs by Nat
Pryce & Duncan McGregor What is failure?
None
Programs can go wrong for so many reasons • Invalid
input ◦ Strings with invalid values ◦ Numbers out of range ◦ Unexpectedly null pointers exceptions • External failure ◦ File not found ◦ Timeouts • Programming errors ◦ Array out of bound ◦ Invalid state • System error ◦ Out of memory
https://dart.dev/guides/libraries/library-tour#exceptions Exceptions are considered conditions that you can plan ahead
for and catch. Errors are conditions that you don’t expect or plan for.
https://flutter.dev/docs/testing/errors How Flutter handle errors
None
FlutterError.onError = (FlutterErrorDetails details) { FlutterError.dumpErrorToConsole(details); if (kReleaseMode) { exit(1);
// Report problem and track it } };
/// This is an [FlutterErrorDetails], appears instead of the red
screen /// to avoid scare the users ErrorWidget.builder = (FlutterErrorDetails details) => CustomErrorWidget(); ... class CustomErrorWidget extends StatelessWidget { @override Widget build(BuildContext context) { // Your custom error widget } }
/// This is an [FlutterErrorDetails], appears instead of the red
screen /// to avoid scare the users ErrorWidget.builder = (FlutterErrorDetails details) => CustomErrorWidget(); ... class CustomErrorWidget extends StatelessWidget { @override Widget build(BuildContext context) { // Your custom error widget } }
An example of error handling in Flutter A strategy
class Failure { final String message; final int statusCode; Failure(this.message,
this.statusCode); @override String toString() => "Error $statusCode. $message."; }
Future<List<HotelModel>> getHotels() async { try { final data = await
http.get(_baseUrl + _endPoint); final responseList = json.decode(data.body); return [for (final hotel in responseList) HotelModel.fromJson(hotel)]; } on SocketException { throw Failure("No internet connection", 400); } on HttpException { throw Failure("Not found request", 404); } on FormatException { throw Failure("Invalid JSON format", 666); } catch (e) { throw Failure("Unknown error", 888); } }
Future<List<HotelModel>> getHotels() async { try { final data = await
http.get(_baseUrl + _endPoint); final responseList = json.decode(data.body); return [for (final hotel in responseList) HotelModel.fromJson(hotel)]; } on SocketException { throw Failure("No internet connection", 400); } on HttpException { throw Failure("Not found request", 404); } on FormatException { throw Failure("Invalid JSON format", 666); } catch (e) { throw Failure("Unknown error", 888); } }
void retrieveHotels() async { try { _hotels = await repository.fetchHotels();
} on Failure catch (e) { _failure = e; } notifyListeners(); }
if (hotelBloc.failure != null) { return Center(child: Text(hotelBloc.failure.toString())); } ...
// The other widgets
Catcher Catcher is Flutter plugin which automatically catches error/exceptions and
handle them. Catcher offers mutliple way to handle errors https://pub.dev/packages/catcher
Enzo Lizama • https://github.com/enzoftware/hotel_booking_app • https://www.youtube.com/watch?v=pvYAQNT4o0I • https://flutter.dev/docs/testing/errors Utils resources
Thanks! @enzoftware