Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Error handling in Flutter
Search
Enzo Lizama Paredes
May 22, 2020
Programming
120
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
100
Adding Flutter to an existing Android/iOS app
enzoftware
0
180
Flutter flavors
enzoftware
0
92
Flutter CI/CD with Fastlane
enzoftware
0
90
Flutter Animations
enzoftware
0
72
Productivity tools 4 developers
enzoftware
0
59
OpenCV + Android
enzoftware
1
78
Anko Superpowers
enzoftware
0
85
Mobile Vision API + Android
enzoftware
0
74
Other Decks in Programming
See All in Programming
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
150
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
130
[2026-10-14](C)Re:ゼロから始める異世界生活〜始まりの終わりと終わりの始まり〜
tosite
0
160
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
160
作って学ぶSpring BootのAuto Configuration / JJUG Night Seminar 2026-10-19
rshindo
0
210
オーケストレーション記述言語 Katari
yukikurage
0
200
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
4.7k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
430
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
150
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
1.1k
Modernizing iOS Apps
seyfoyun
0
120
Railsバージョンを4倍にした話
optim
0
730
Featured
See All Featured
The Cult of Friendly URLs
andyhume
79
7k
Designing Experiences People Love
moore
143
24k
First, design no harm
axbom
PRO
2
1.4k
Typedesign – Prime Four
hannesfritz
42
3.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
330
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Paper Plane
katiecoart
PRO
5
54k
The Language of Interfaces
destraynor
162
27k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
650
Un-Boring Meetings
codingconduct
0
460
Building the Perfect Custom Keyboard
takai
2
920
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
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