File tree Expand file tree Collapse file tree 5 files changed +28
-12
lines changed
example/lib/features/scene/detail Expand file tree Collapse file tree 5 files changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -99,12 +99,12 @@ extension DetailLogicForListView on DetailLogic {
9999 update (ids);
100100 }
101101
102- /// Show loading first, and hide loading after the ListView is rendered.
103- void firstTimeRenderListView () {
104- WidgetsBinding .instance. addPostFrameCallback ((_) {
105- state.showLoading = false ;
106- update ([ DetailUpdateType .loading]) ;
107- } );
102+ /// Show loading first, and hide loading after setting the index of the
103+ /// TabBar and scrolling to the corresponding module.
104+ void firstTimeRenderListView () async {
105+ await Future . delayed ( const Duration (milliseconds : 100 )) ;
106+ state.showLoading = false ;
107+ update ([ DetailUpdateType .loading] );
108108 }
109109
110110 void loadAsyncDataForListView () {
Original file line number Diff line number Diff line change @@ -17,7 +17,11 @@ mixin DetailStateForListView {
1717
1818 late ListObserverController observerController = ListObserverController (
1919 controller: scrollController,
20- )..cacheJumpIndexOffset = false ;
20+ )
21+ ..observeIntervalForScrolling = const Duration (milliseconds: 50 )
22+ // Since there are modules loaded asynchronously, which will cause the
23+ // cache to be offset inaccurately, so it is set to false here
24+ ..cacheJumpIndexOffset = false ;
2125
2226 late ChatScrollObserver keepPositionObserver = ChatScrollObserver (
2327 observerController,
Original file line number Diff line number Diff line change @@ -8,13 +8,13 @@ import 'package:flutter/material.dart';
88import 'package:scrollview_observer_example/features/scene/detail/header/detail_header.dart' ;
99
1010class DetailListItemWrapper extends StatefulWidget {
11- final String title;
11+ final String ? title;
1212 final Widget child;
1313
1414 const DetailListItemWrapper ({
1515 super .key,
16- required this .title,
1716 required this .child,
17+ this .title,
1818 });
1919
2020 @override
@@ -23,20 +23,25 @@ class DetailListItemWrapper extends StatefulWidget {
2323
2424class _DetailListItemWrapperState extends State <DetailListItemWrapper >
2525 with DetailLogicConsumerMixin <DetailListItemWrapper > {
26+ String get title => widget.title ?? '' ;
27+
2628 @override
2729 Widget build (BuildContext context) {
2830 return Column (
2931 crossAxisAlignment: CrossAxisAlignment .start,
3032 children: [
3133 _buildTitle (),
3234 widget.child,
35+ const SizedBox (height: 10 ),
3336 ],
3437 );
3538 }
3639
3740 Widget _buildTitle () {
41+ if (title.isEmpty) return const SizedBox .shrink ();
42+
3843 Widget resultWidget = Text (
39- widget. title,
44+ title,
4045 style: Theme .of (context).textTheme.titleLarge,
4146 );
4247 resultWidget = Padding (
Original file line number Diff line number Diff line change @@ -90,11 +90,14 @@ class _DetailListViewState extends State<DetailListView>
9090 }
9191 },
9292 separatorBuilder: (context, index) {
93- return const Divider ();
93+ return Container (
94+ color: Colors .black12,
95+ height: 1 ,
96+ );
9497 },
9598 itemCount: moduleTypes.length,
9699 // Set a large enough cacheExtent to ensure that the keep position
97- // function can work properly.
100+ // functionality can work properly.
98101 //
99102 // More information and tips:
100103 // https://github.com/fluttercandies/flutter_scrollview_observer/wiki/3%E3%80%81Chat-Observer
Original file line number Diff line number Diff line change 66
77import 'package:flutter/material.dart' ;
88import 'package:scrollview_observer_example/features/scene/detail/header/detail_header.dart' ;
9+ import 'package:scrollview_observer_example/features/scene/detail/widget/detail_list_item_wrapper.dart' ;
910
1011class DetailListModule1 extends StatefulWidget {
1112 const DetailListModule1 ({super .key});
@@ -19,6 +20,9 @@ class _DetailListModule1State extends State<DetailListModule1>
1920 @override
2021 Widget build (BuildContext context) {
2122 Widget resultWidget = _buildPageView ();
23+ resultWidget = DetailListItemWrapper (
24+ child: resultWidget,
25+ );
2226 return resultWidget;
2327 }
2428
You can’t perform that action at this time.
0 commit comments