From d52eb50e391c817256613083ec08db6dd5fe194d Mon Sep 17 00:00:00 2001 From: endless7 Date: Tue, 6 Sep 2022 16:46:17 +0800 Subject: [PATCH] chore: add loadMore example. --- example/lib/pages/loadMore_page.dart | 2 +- example/lib/pages/position_page.dart | 178 +++++++++++++-------------- 2 files changed, 84 insertions(+), 96 deletions(-) diff --git a/example/lib/pages/loadMore_page.dart b/example/lib/pages/loadMore_page.dart index e2090c4..c092d44 100644 --- a/example/lib/pages/loadMore_page.dart +++ b/example/lib/pages/loadMore_page.dart @@ -43,7 +43,7 @@ class _LoadMoreExampleState extends State { onPressed: () { _positionController.scrollTo(10); }, - child: const Text("scrollTo10"), + child: const Text("scroll10"), ), ], ); diff --git a/example/lib/pages/position_page.dart b/example/lib/pages/position_page.dart index 456ed59..3fda9d3 100644 --- a/example/lib/pages/position_page.dart +++ b/example/lib/pages/position_page.dart @@ -50,88 +50,80 @@ class _ScrollablePositionedListPageState } @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: Text("Position")), - body: OrientationBuilder( - builder: (context, orientation) => - Column( - children: [ - Expanded( - child: list1(), - // child: list(orientation), - ), - Container( - height: 100, - child: Row( - children: [ - Column( - children: [ - scrollControlButtons, - jumpControlButtons, - ], - ), - ], - ) - ) - ], - ), + Widget build(BuildContext context) => Material( + child: OrientationBuilder( + builder: (context, orientation) => Column( + children: [ + Expanded( + child: list1(), + // child: list(orientation), + ), + Container( + height: 100, + child: Row( + children: [ + Column( + children: [ + scrollControlButtons, + jumpControlButtons, + // alignmentControl, + ], + ), + ], + ) + ) + ], ), - ); - } - - Widget get alignmentControl => Row( - mainAxisSize: MainAxisSize.max, - children: [ - const Text('Alignment: '), - SizedBox( - width: 100, - child: SliderTheme( - data: SliderThemeData( - showValueIndicator: ShowValueIndicator.always, - ), - child: Slider( - value: alignment, - label: alignment.toStringAsFixed(2), - onChanged: (double value) => setState(() => alignment = value), - ), + ), + ); + + Widget get alignmentControl => Row( + mainAxisSize: MainAxisSize.max, + children: [ + const Text('Alignment: '), + SizedBox( + width: 100, + child: SliderTheme( + data: SliderThemeData( + showValueIndicator: ShowValueIndicator.always, + ), + child: Slider( + value: alignment, + label: alignment.toStringAsFixed(2), + onChanged: (double value) => setState(() => alignment = value), ), ), - ], - ); + ), + ], + ); - late SKPositionController controller; - - List data = () { - List data = []; - for (var i = -40; i < -10; i++) { - data.add(TempData()..index = i); - } - for (var i = -10; i < 0; i++) { - data.add(TempData()..index = i); - } - for (var i = 0; i < 10; i++) { - data.add(TempData()..index = i); - } - return data; - }(); - - Widget list1() { - controller = SKPositionController( - viewportBoundaryGetter: () => - Rect.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom), - axis: Axis.vertical - ); + late SKPositionController controller; + + List data = () { + List data = []; + for (var i = 0; i < 50; i++) { + data.add(i); + } + return data; + }(); + + Widget list1() { - return SKPositionedList( - controller: controller, - delegate: SKSliverChildBuilderDelegate( + controller = SKPositionController( + viewportBoundaryGetter: () => + Rect.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom), + axis: Axis.vertical + ); + + return SKPositionedList( + controller: controller, + delegate: SKSliverChildBuilderDelegate( (context, index) { return Container( height: 80, color: Colors.grey, child: Center( - child: Text(data[index].index.toString()), + child: Text(data[index].toString()), ), ); }, @@ -141,25 +133,25 @@ class _ScrollablePositionedListPageState ); } - Widget get scrollControlButtons => Row( - children: [ - const SizedBox(child: Text('scroll to'), height: 40,), - scrollButton(0), - scrollButton(5), - scrollButton(10), - scrollButton(30), - ], - ); - - Widget get jumpControlButtons => Row( - children: [ - const SizedBox(child: Text('jump to'), height: 40,), - jumpButton(0), - jumpButton(5), - jumpButton(10), - jumpButton(30), - ], - ); + Widget get scrollControlButtons => Row( + children: [ + const Text('scroll to'), + scrollButton(0), + scrollButton(5), + scrollButton(10), + scrollButton(30), + ], + ); + + Widget get jumpControlButtons => Row( + children: [ + const Text('jump to'), + jumpButton(0), + jumpButton(5), + jumpButton(10), + jumpButton(30), + ], + ); final _scrollButtonStyle = ButtonStyle( padding: MaterialStateProperty.all( @@ -207,7 +199,3 @@ class _ScrollablePositionedListPageState ); } } - -class TempData { - int? index; -}