Hello everyone I am trying to build a reusable SliverList into which I just pass the sliver widgets as a List to display, and doubles for padding however currently getting this error
The code of the reusable widget I am trying to build
class ScrollScreen extends StatelessWidget {
ScrollScreen({
@required this.pageTitle,
@required this.pageImage,
@required this.widgets,
this.color = Colors.white,
});
final String pageTitle;
final String pageImage;
final List<Widget> widgets;
final Color color;
@override
Widget build(BuildContext context) {
return CustomScrollView(physics: const BouncingScrollPhysics(), slivers: [
SliverBar(title: pageTitle, image: pageImage),
SliverListLayout(widgets: widgets),
]);
}
Class of SliverListLayout
class SliverListLayout extends StatelessWidget {
final double paddingTB;
final double paddingLR;
final List<Widget> widgets;
SliverListLayout({
@required this.widgets,
this.paddingTB,
this.paddingLR,
});
@override
Widget build(BuildContext context) {
return SliverList(
delegate: SliverChildListDelegate([
...addPadding(widgets, paddingTB, paddingLR), //add padding wraps widgets in a padding widget and returns them,, not the issue works fine elsewhere
]),
);
}
} StackTrace:
The following NoSuchMethodError was thrown building
NotificationListener<KeepAliveNotification>:
The method '>=' was called on null.
Receiver: null
Tried calling: >=(0.0)
The relevant error-causing widget was
SliverList
lib\…\custom_widgets\sliverlist_layout.dart:15
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 EdgeInsetsGeometry.isNonNegative
package:flutter/…/painting/edge_insets.dart:52
#2 new RenderPadding
package:flutter/…/rendering/shifted_box.dart:107
#3 Padding.createRenderObject
package:flutter/…/widgets/basic.dart:1652
#4 RenderObjectElement.mount
Flutter Doctor:
PS C:\Users\Usuario\Desktop\AppName> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Versión 10.0.19042.746], locale es-ES)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 4.1.0)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.52.1)
[√] Connected device (1 available)
! Doctor found issues in 2 categories.
PS C:\Users\Usuario\Desktop\AppName>
addPadding
List<Widget> addPadding(List<Widget> widgets,
[double paddingTB = 25.0, double paddingLR = 25.0]) {
for (int i = 0; i < widgets.length; i++) {
widgets[i] = Padding(
padding: EdgeInsets.fromLTRB(
paddingLR,
paddingTB,
paddingLR,
paddingTB,
),
child: widgets[i],
);
}
return widgets;
}
I paste the code from the SliverListLayout class (without the two extra parameters) and everything works fine. Also SliverBar returns a SliverAppBar, and it works fine. Any help is very appreciated.