티스토리 뷰
Before
- There was no null-handling in the method "firstWhere" which throws an error "Bad State" once it returns "null" value.
String? title = e.inspections
.firstWhere((e) => e.name == inspection.name)
.value;
text = Text( title ?? '-');
After
- Add "orElse" caluse inside the method but note that value "null" is unavailable to set. In my case, the returned value is an object of "Inspection" that is why I set "null" as a value of a field "value" in a singular object. Value is also availble to be "" (empty string). Briefly, your "null" value without encapsulating is UNavailable.
String? title = e.inspections
.firstWhere((e) => e.name == inspection.name,
orElse: () => Inspection(value: null))
.value;
text = Text( title ?? '-');
👨🏫 Recommendation
- Highly recommend to use "collection" package to handle null easily. It provides "firstWhereOrNull", "lastWhereOrNull", "singleWhereOrNull".
import 'package:collection/collection.dart';
final prevIns = prevCheckUp!.inspections.firstWhereOrNull(
(e) => e.key == inspection.key,
);
'App > Flutter' 카테고리의 다른 글
Flutter Rive - make your app dynamic (0) | 2023.02.16 |
---|---|
A RenderShrinkWrappingViewport expected a child of type RenderSliver but received a child of type RenderConstrainedBox. (0) | 2023.02.14 |
Flutter Hook - Summary (2) | 2023.02.01 |
table_calendar is not scrollable vertically inside ListView/SingleChildScrollView (0) | 2023.01.31 |
iOS App Distribution #2 - APNs key && iOS Setup for FCM (0) | 2022.12.14 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- flutter_storage_not_working_for_the_first_time
- querydslQclass
- retrofit_generator_conflicts_with_freezed
- flutter_secure_storage_issue_iOS
- mvvm
- futter_api
- unsplashAPI
- flutter_android_app_links
- android_app_link_domain_works_with_adb_but_not_works_with_browser
- Kotlin
- querydsl5.0.0jakarta
- retrofit_toJson()_error
- AndroidWirelessDebug
- Android
- dagger-hilt
- FlutterWirelessDebuginAOS
- flutter
- android_app_links
- Laravel
- KotlinFlow
- phplaravel
- MultipleFirebaseEnvironments
- RunAFlutterProjectIniPhoneFromVSCode
- android_domain
- WirelessDebug
- laravel9
- querydslKotlinError
- retrofit_generator
- android_app_links_domain
- FirebaseConfigurationForMultipleBuildTypes
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함