Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Flutter analyze

on:
pull_request:
branches: [main, dev]
branches: [master, dev]

jobs:
flutter-analyze:
Expand All @@ -22,7 +22,7 @@ jobs:
run: dart format . --set-exit-if-changed

- name: Analyze project source
run: dart analyze --no-pub
run: dart analyze

- name: Install pana
run: dart pub global activate pana
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Flutter Scroll Shadow

## [1.2.6] - 2024-01-14
#### [@rickypid](https://github.com/rickypid)
- Replaced `withOpacity` with `withAlpha`

## [1.2.5] - 2024-01-14
#### [@rickypid](https://github.com/rickypid)
- Fixed shadow display bug with Scroll reverse to true - (#16)
Expand Down
21 changes: 18 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ include: package:flutter_lints/flutter.yaml

linter:
rules:
always_use_package_imports: true
prefer_single_quotes: true
unnecessary_breaks: true
- always_declare_return_types
- avoid_unused_constructor_parameters
- directives_ordering
- omit_local_variable_types
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
- sized_box_for_whitespace
- sort_child_properties_last
- sort_pub_dependencies
- type_annotate_public_apis
- unawaited_futures
- use_named_constants
- use_super_parameters
- require_trailing_commas

18 changes: 17 additions & 1 deletion example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,21 @@ include: package:flutter_lints/flutter.yaml

linter:
rules:
always_use_package_imports: true
- always_declare_return_types
- avoid_unused_constructor_parameters
- directives_ordering
- omit_local_variable_types
- prefer_expression_function_bodies
- prefer_final_fields
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
- sized_box_for_whitespace
- sort_child_properties_last
- sort_pub_dependencies
- type_annotate_public_apis
- unawaited_futures
- use_named_constants
- use_super_parameters
- require_trailing_commas

87 changes: 42 additions & 45 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,65 @@ class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ScrollShadow Example',
theme: ThemeData(primarySwatch: Colors.blue),
home: const MyHomePage(),
);
}
Widget build(BuildContext context) => MaterialApp(
title: 'ScrollShadow Example',
theme: ThemeData(primarySwatch: Colors.blue),
home: const MyHomePage(),
);
}

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

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
' Vertical | Horizontal'),
centerTitle: true,
),
body: Row(
children: [
// Vertically-scrolling child
Expanded(
child: ScrollShadow(
color: Colors.grey,
child: ListView(
scrollDirection: Axis.vertical,
children: List.generate(
15,
(index) => ListTile(title: Text('Element $index')),
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text(
' Vertical | Horizontal',
),
centerTitle: true,
),
body: Row(
children: [
// Vertically-scrolling child
Expanded(
child: ScrollShadow(
color: Colors.grey,
child: ListView(
scrollDirection: Axis.vertical,
children: List.generate(
15,
(index) => ListTile(title: Text('Element $index')),
),
),
),
),
),

// Horizontally-scrolling child
Expanded(
child: ScrollShadow(
color: Colors.grey,
child: ListView(
scrollDirection: Axis.horizontal,
children: List.generate(
5,
(index) => SizedBox(
width: 100,
child: RotatedBox(
quarterTurns: 1,
child: Text('Element $index'),
// Horizontally-scrolling child
Expanded(
child: ScrollShadow(
color: Colors.grey,
child: ListView(
scrollDirection: Axis.horizontal,
children: List.generate(
5,
(index) => SizedBox(
width: 100,
child: RotatedBox(
quarterTurns: 1,
child: Text('Element $index'),
),
),
),
),
),
),
),
],
),
);
}
],
),
);
}
12 changes: 6 additions & 6 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
url: "https://pub.dev"
source: hosted
version: "2.0.3"
version: "5.0.0"
flutter_scroll_shadow:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.2.5"
version: "1.2.6"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -118,10 +118,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "5.0.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -240,5 +240,5 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.4.0 <4.0.0"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_scroll_shadow_example
description: A demonstration of the ScrollShadow widget for a scrollable child.
version: 1.2.4
version: 1.2.6
publish_to: 'none'

environment:
Expand All @@ -13,9 +13,9 @@ dependencies:
path: ../

dev_dependencies:
flutter_lints: ^5.0.0
flutter_test:
sdk: flutter
flutter_lints: ^2.0.2
import_sorter: ^4.6.0

flutter:
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_scroll_shadow.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Adds `ScrollShadow` widget to add shadows to a scrollable child. Supports ScrollController and vertical or horizontal orientation.
library flutter_scroll_shadow;
library;

export 'src/scroll_shadow.dart';
90 changes: 43 additions & 47 deletions lib/src/scroll_shadow.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// [ScrollShadow] class
library flutter_scroll_shadow;
library;

import 'package:flutter/material.dart';

Expand Down Expand Up @@ -83,23 +83,23 @@ class _ScrollShadowState extends State<ScrollShadow> {
startGradient = LinearGradient(
begin: Alignment.centerRight,
end: Alignment.centerLeft,
colors: [widget.color.withOpacity(0.0), widget.color],
colors: [widget.color.withAlpha(0), widget.color],
);
endGradient = LinearGradient(
begin: Alignment.centerRight,
end: Alignment.centerLeft,
colors: [widget.color, widget.color.withOpacity(0.0)],
colors: [widget.color, widget.color.withAlpha(0)],
);
case Axis.vertical:
startGradient = LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [widget.color.withOpacity(0.0), widget.color],
colors: [widget.color.withAlpha(0), widget.color],
);
endGradient = LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [widget.color, widget.color.withOpacity(0.0)],
colors: [widget.color, widget.color.withAlpha(0)],
);
}
var startShadow = _getShadow(startGradient);
Expand All @@ -114,51 +114,47 @@ class _ScrollShadowState extends State<ScrollShadow> {
}
startShadow = _getPositioned(startShadow, true);
endShadow = _getPositioned(endShadow, false);
return Stack(children: [
NotificationListener<ScrollMetricsNotification>(
onNotification: (notification) {
return _handleNewMetrics(notification.metrics);
},
child: NotificationListener<ScrollNotification>(
onNotification: (notification) {
return _handleNewMetrics(notification.metrics);
},
child: widget.child,
return Stack(
children: [
NotificationListener<ScrollMetricsNotification>(
onNotification: (notification) =>
_handleNewMetrics(notification.metrics),
child: NotificationListener<ScrollNotification>(
onNotification: (notification) =>
_handleNewMetrics(notification.metrics),
child: widget.child,
),
),
),
if (startShadow != null) startShadow,
if (endShadow != null) endShadow,
]);
if (startShadow != null) startShadow,
if (endShadow != null) endShadow,
],
);
}

Widget? _getShadow(final LinearGradient? gradient) {
return gradient == null
? null
: Container(
width: widget.size,
height: widget.size,
decoration: BoxDecoration(gradient: gradient));
}

Widget? _getAnimatedShadow(final Widget? shadow, final bool reachedEdge) {
return shadow == null
? null
: AnimatedOpacity(
opacity: reachedEdge ? 0.0 : 1.0,
duration: widget.duration,
curve: reachedEdge ? widget.fadeOutCurve : widget.fadeInCurve,
child: shadow,
);
}
Widget? _getShadow(final LinearGradient? gradient) => gradient == null
? null
: Container(
width: widget.size,
height: widget.size,
decoration: BoxDecoration(gradient: gradient),
);

Widget? _getNoninteractive(final Widget? shadow) {
return shadow == null
? null
: IgnorePointer(
ignoring: true,
child: shadow,
);
}
Widget? _getAnimatedShadow(final Widget? shadow, final bool reachedEdge) =>
shadow == null
? null
: AnimatedOpacity(
opacity: reachedEdge ? 0.0 : 1.0,
duration: widget.duration,
curve: reachedEdge ? widget.fadeOutCurve : widget.fadeInCurve,
child: shadow,
);

Widget? _getNoninteractive(final Widget? shadow) => shadow == null
? null
: IgnorePointer(
ignoring: true,
child: shadow,
);

Widget? _getPositioned(final Widget? shadow, final bool start) {
if (shadow == null) return null;
Expand Down Expand Up @@ -188,7 +184,7 @@ class _ScrollShadowState extends State<ScrollShadow> {
if (_axis != metrics.axis) {
setState(() => _axis = metrics.axis);
}
final bool isReverse = metrics.axisDirection == AxisDirection.left ||
final isReverse = metrics.axisDirection == AxisDirection.left ||
metrics.axisDirection == AxisDirection.up;
reachedStart = isReverse
? metrics.pixels >= metrics.maxScrollExtent
Expand Down
Loading
Loading