티스토리 뷰
App/Flutter
A RenderShrinkWrappingViewport expected a child of type RenderSliver but received a child of type RenderConstrainedBox.
Agrafenaaa 2023. 2. 14. 16:31ISSUE : CustomScrollView widget which consists of SlivderList(SliverChildBuilderDelegate) and is supported by riverpod state management suddenly occured the error below. Sliver-related widget doesn't show the specified widget from provider's when method (error: (err, stackTrace) => const SizedBox()) and throws an exception
Error Output
Code:
list() {
final notifications = ref.watch(notificationProvider);
return Expanded(
child: NotificationListener<ScrollEndNotification>(
child: Scrollbar(
thickness: 0,
child: RefreshIndicator(
onRefresh: () async {
ref.read(notificationProvider.notifier).getList();
},
child: CustomScrollView(
shrinkWrap: true,
restorationId: 'notifications',
slivers: <Widget>[
notifications.when(data: (data) {
context.loaderOverlay.hide();
return SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, idx) => _push(notification: data[idx]),
childCount: data.length,
),
);
}, loading: () {
context.loaderOverlay.show(widget: const Spinner());
return const SizedBox();
}, error: (err, stackTrace) {
if (notifications.hasValue) {
return SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, idx) =>
_push(notification: notifications.value![idx]),
childCount: notifications.value!.length,
),
);
}
return const SizedBox();
}),
LazyLoadingBottom(asyncValue: notifications),
],
),
),
),
),
);
}
Solution 1 -> Add an additional condition if the data is empty. (Failed)
notifications.when(data: (data) {
context.loaderOverlay.hide();
if (data.isNotEmpty) {
return SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, idx) => _push(notification: data[idx]),
childCount: data.length,
),
);
} else {
return const SizedBox();
}
Solution 2 -> Check if the data object field name has changed. (applicable partly)
ex) NotificationModel => topicType json key has changed from "msg_notice" to "msgNotice".
Solution 3 -> Reorder widget tree. NotificationListener should be inside "data" instead of putting list provider when method INSIDE "NotificationListener" to avoid errors.
Expanded(
child: notifications.when(
data: (data) {
if (data.isNotEmpty) {
return NotificationListener<ScrollEndNotification>(
child: Scrollbar(
thickness: 0,
child: RefreshIndicator(
onRefresh: () async {
ref
.refresh(notificationProvider.notifier)
.getList();
},
child: CustomScrollView(
shrinkWrap: true,
restorationId: 'notifications',
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, idx) => _push(notification: data[idx]),
childCount: data.length,
),
),
LazyLoadingBottom(asyncValue: notifications),
],
),
),
),
);
} else {
return const SizedBox();
}
},
loading: () => const Spinner(),
error: (error, stackTrace) => const SizedBox(),
),
),
'App > Flutter' 카테고리의 다른 글
Flutter - How to get a global BuildContext to use anywhere? (0) | 2023.02.22 |
---|---|
Flutter Rive - make your app dynamic (0) | 2023.02.16 |
where, firstWhere -> Bad state: No element (0) | 2023.02.09 |
Flutter Hook - Summary (2) | 2023.02.01 |
table_calendar is not scrollable vertically inside ListView/SingleChildScrollView (0) | 2023.01.31 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- retrofit_generator_conflicts_with_freezed
- android_app_links
- Kotlin
- laravel9
- FlutterWirelessDebuginAOS
- unsplashAPI
- flutter_secure_storage_issue_iOS
- dagger-hilt
- android_domain
- flutter_storage_not_working_for_the_first_time
- mvvm
- flutter
- flutter_android_app_links
- Android
- android_app_links_domain
- WirelessDebug
- MultipleFirebaseEnvironments
- FirebaseConfigurationForMultipleBuildTypes
- querydslQclass
- querydslKotlinError
- AndroidWirelessDebug
- android_app_link_domain_works_with_adb_but_not_works_with_browser
- KotlinFlow
- phplaravel
- Laravel
- futter_api
- retrofit_generator
- querydsl5.0.0jakarta
- retrofit_toJson()_error
- RunAFlutterProjectIniPhoneFromVSCode
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함