Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 2.0.0
- Breaking Changes
- Require Dart SDK `^3.13.0` and Flutter `>=3.47.0`.
- Migrate from `package:flutter/material.dart` to `package:material_ui` and add it as a dependency.
- ObserverController
- Fix local variable shadowing errors of `controller` reported by the analyzer.
- Guard `BuildContext` usage across async gaps with `mounted` checks.
- ObserverWidget
- Fix local variable shadowing error of `scopeContext` reported by the analyzer.
- Guard `BuildContext` usage across async gaps with `mounted` checks.
- ChatScrollObserver
- Fix self-assignment of `innerRefItemIndex`, `innerRefItemIndexAfterUpdate` and `innerRefItemLayoutOffset` in `standby`.
- Guard `BuildContext` usage across async gaps with `mounted` checks.
- Others
- Upgrade `flutter_lints` to `^6.0.0` and resolve all analyzer issues in the package and example.
- Adopt super parameters, `base` class modifiers and remove leading underscores from local identifiers.
- Replace the outdated counter smoke test of the example with a home page smoke test.

## 1.27.1
- ObserverController
- Correct the scrolling clamped by an outdated `scrollExtent` by @LinXunFeng in [#150](https://github.com/fluttercandies/flutter_scrollview_observer/issues/150).
Expand Down
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
analyzer:
exclude:
- build/**
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
Expand Down
9 changes: 9 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
analyzer:
exclude:
- build/**
- android/**
- ios/**
- web/**
- windows/**
- macos/**
- linux/**
include: package:flutter_lints/flutter.yaml

linter:
Expand Down
17 changes: 4 additions & 13 deletions example/lib/common/route/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Date: 2025-08-02 15:49:58
*/

import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:go_router/go_router.dart';

class NavigationService {
Expand All @@ -13,22 +13,13 @@ class NavigationService {

static BuildContext get context => navigatorKey.currentState!.context;

static void push(
String location, {
Object? extra,
}) {
context.push(
location,
extra: extra,
);
static void push(String location, {Object? extra}) {
context.push(location, extra: extra);
}

static void pop() => context.pop();

static dynamic getParam(
String key, {
dynamic defaultValue,
}) {
static dynamic getParam(String key, {dynamic defaultValue}) {
final state = routerState();
final pathParam = state.pathParameters[key];
if (pathParam != null) return pathParam;
Expand Down
16 changes: 4 additions & 12 deletions example/lib/common/route/router_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:go_router/go_router.dart';
import 'package:scrollview_observer_example/common/route/route.dart';
import 'package:scrollview_observer_example/features/custom_scrollview/custom_scrollview_demo/custom_scrollview_center_demo_page.dart';
Expand Down Expand Up @@ -101,18 +101,13 @@ class MyRoute {
static final routerConfig = GoRouter(
routes: routes,
initialLocation: MyPage.home,
observers: [
observer,
],
observers: [observer],
navigatorKey: NavigationService.navigatorKey,
debugLogDiagnostics: !kReleaseMode,
);

static final List<RouteBase> routes = [
GoRoute(
path: MyPage.home,
builder: (context, state) => const HomePage(),
),
GoRoute(path: MyPage.home, builder: (context, state) => const HomePage()),
GoRoute(
path: MyPage.listView,
builder: (context, state) => const ListViewDemoPage(),
Expand Down Expand Up @@ -221,10 +216,7 @@ class MyRoute {
path: MyPage.imageTab,
builder: (context, state) => const ImageTabPage(),
),
GoRoute(
path: MyPage.chat,
builder: (context, state) => const ChatPage(),
),
GoRoute(path: MyPage.chat, builder: (context, state) => const ChatPage()),
GoRoute(
path: MyPage.chatGPT,
builder: (context, state) => const ChatGPTPage(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* @Date: 2024-03-11 21:08:23
*/

import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:scrollview_observer/scrollview_observer.dart';
import 'package:scrollview_observer_example/utils/snackbar.dart';

class CustomScrollViewCenterDemoPage extends StatefulWidget {
const CustomScrollViewCenterDemoPage({Key? key}) : super(key: key);
const CustomScrollViewCenterDemoPage({super.key});

@override
State<CustomScrollViewCenterDemoPage> createState() =>
Expand Down Expand Up @@ -49,10 +49,10 @@ class _CustomScrollViewCenterDemoPageState
child: _buildScrollView(),
sliverContexts: () {
return [
if (_sliverListCtx1 != null) _sliverListCtx1!,
if (_sliverListCtx2 != null) _sliverListCtx2!,
if (_sliverListCtx3 != null) _sliverListCtx3!,
if (_sliverListCtx4 != null) _sliverListCtx4!,
?_sliverListCtx1,
?_sliverListCtx2,
?_sliverListCtx3,
?_sliverListCtx4,
];
},
onObserveAll: (resultMap) {
Expand Down Expand Up @@ -203,23 +203,20 @@ class _CustomScrollViewCenterDemoPageState
Function(BuildContext)? onBuild,
}) {
return SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, index) {
onBuild?.call(ctx);
final int itemIndex = index ~/ 2;
return Container(
height: (itemIndex % 2 == 0) ? 80 : 50,
color: color,
child: Center(
child: Text(
"index -- $index",
style: const TextStyle(color: Colors.white),
),
delegate: SliverChildBuilderDelegate((ctx, index) {
onBuild?.call(ctx);
final int itemIndex = index ~/ 2;
return Container(
height: (itemIndex % 2 == 0) ? 80 : 50,
color: color,
child: Center(
child: Text(
"index -- $index",
style: const TextStyle(color: Colors.white),
),
);
},
childCount: 100,
),
),
);
}, childCount: 100),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
* @Repo: https://github.com/LinXunFeng/flutter_scrollview_observer
* @Date: 2022-08-08 00:20:03
*/
import 'package:flutter/material.dart';
import 'package:material_ui/material_ui.dart';
import 'package:scrollview_observer/scrollview_observer.dart';
import 'package:scrollview_observer_example/typedefs.dart';
import 'package:scrollview_observer_example/utils/snackbar.dart';

class CustomScrollViewDemoPage extends StatefulWidget {
const CustomScrollViewDemoPage({Key? key}) : super(key: key);
const CustomScrollViewDemoPage({super.key});

@override
State<CustomScrollViewDemoPage> createState() =>
Expand All @@ -35,9 +35,7 @@ class _CustomScrollViewDemoPageState extends State<CustomScrollViewDemoPage> {

// Trigger an observation manually
ambiguate(WidgetsBinding.instance)?.addPostFrameCallback((timeStamp) {
observerController.dispatchOnceObserve(
sliverContext: _sliverListCtx!,
);
observerController.dispatchOnceObserve(sliverContext: _sliverListCtx!);
});
}

Expand All @@ -55,10 +53,7 @@ class _CustomScrollViewDemoPageState extends State<CustomScrollViewDemoPage> {
controller: observerController,
child: _buildScrollView(),
sliverContexts: () {
return [
if (_sliverListCtx != null) _sliverListCtx!,
if (_sliverGridCtx != null) _sliverGridCtx!,
];
return [?_sliverListCtx, ?_sliverGridCtx];
},
onObserveAll: (resultMap) {
final model1 = resultMap[_sliverListCtx];
Expand All @@ -80,8 +75,9 @@ class _CustomScrollViewDemoPageState extends State<CustomScrollViewDemoPage> {
debugPrint('2 visible -- ${model2.visible}');
debugPrint('2 displaying -- ${model2.displayingChildIndexList}');
setState(() {
_hitIndexsForGrid =
model2.firstGroupChildList.map((e) => e.index).toList();
_hitIndexsForGrid = model2.firstGroupChildList
.map((e) => e.index)
.toList();
});
}
},
Expand Down Expand Up @@ -131,10 +127,7 @@ class _CustomScrollViewDemoPageState extends State<CustomScrollViewDemoPage> {
return CustomScrollView(
controller: scrollController,
// scrollDirection: Axis.horizontal,
slivers: [
_buildSliverListView(),
_buildSliverGridView(),
],
slivers: [_buildSliverListView(), _buildSliverGridView()],
);
}

Expand Down Expand Up @@ -162,25 +155,21 @@ class _CustomScrollViewDemoPageState extends State<CustomScrollViewDemoPage> {
// itemExtent: 100,
// );
return SliverList(
delegate: SliverChildBuilderDelegate(
(ctx, index) {
_sliverListCtx ??= ctx;
return Container(
height: (index % 2 == 0) ? 80 : 50,
color: _hitIndexForCtx1 == index ? Colors.red : Colors.black12,
child: Center(
child: Text(
"index -- $index",
style: TextStyle(
color:
_hitIndexForCtx1 == index ? Colors.white : Colors.black,
),
delegate: SliverChildBuilderDelegate((ctx, index) {
_sliverListCtx ??= ctx;
return Container(
height: (index % 2 == 0) ? 80 : 50,
color: _hitIndexForCtx1 == index ? Colors.red : Colors.black12,
child: Center(
child: Text(
"index -- $index",
style: TextStyle(
color: _hitIndexForCtx1 == index ? Colors.white : Colors.black,
),
),
);
},
childCount: 30,
),
),
);
}, childCount: 30),
);
}

Expand All @@ -192,20 +181,15 @@ class _CustomScrollViewDemoPageState extends State<CustomScrollViewDemoPage> {
crossAxisSpacing: 10.0,
childAspectRatio: 2.0,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
_sliverGridCtx ??= context;
return Container(
color: (_hitIndexsForGrid.contains(index))
? Colors.green
: Colors.blue[100],
child: Center(
child: Text('index -- $index'),
),
);
},
childCount: 150,
),
delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
_sliverGridCtx ??= context;
return Container(
color: (_hitIndexsForGrid.contains(index))
? Colors.green
: Colors.blue[100],
child: Center(child: Text('index -- $index')),
);
}, childCount: 150),
);
}
}
Loading