diff --git a/.github/workflows/flutter.yml b/.github/workflows/flutter.yml index 3884a55..26e7baf 100644 --- a/.github/workflows/flutter.yml +++ b/.github/workflows/flutter.yml @@ -2,7 +2,7 @@ name: Flutter analyze on: pull_request: - branches: [main, dev] + branches: [master, dev] jobs: flutter-analyze: @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 67127a6..dc117d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/analysis_options.yaml b/analysis_options.yaml index d82c5ef..18f9502 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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 + diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml index dcac157..18f9502 100644 --- a/example/analysis_options.yaml +++ b/example/analysis_options.yaml @@ -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 diff --git a/example/lib/main.dart b/example/lib/main.dart index 0482b03..e539610 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -10,17 +10,15 @@ 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 createState() => _MyHomePageState(); @@ -28,50 +26,49 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { @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'), + ), ), ), ), ), ), - ), - ], - ), - ); - } + ], + ), + ); } diff --git a/example/pubspec.lock b/example/pubspec.lock index 308dda0..ff223c2 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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 @@ -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: @@ -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" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 94168a4..d56d8c6 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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: @@ -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: diff --git a/lib/flutter_scroll_shadow.dart b/lib/flutter_scroll_shadow.dart index 9f66aca..901f5e2 100644 --- a/lib/flutter_scroll_shadow.dart +++ b/lib/flutter_scroll_shadow.dart @@ -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'; diff --git a/lib/src/scroll_shadow.dart b/lib/src/scroll_shadow.dart index e4ec66b..8cec4ad 100644 --- a/lib/src/scroll_shadow.dart +++ b/lib/src/scroll_shadow.dart @@ -1,5 +1,5 @@ /// [ScrollShadow] class -library flutter_scroll_shadow; +library; import 'package:flutter/material.dart'; @@ -83,23 +83,23 @@ class _ScrollShadowState extends State { 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); @@ -114,51 +114,47 @@ class _ScrollShadowState extends State { } startShadow = _getPositioned(startShadow, true); endShadow = _getPositioned(endShadow, false); - return Stack(children: [ - NotificationListener( - onNotification: (notification) { - return _handleNewMetrics(notification.metrics); - }, - child: NotificationListener( - onNotification: (notification) { - return _handleNewMetrics(notification.metrics); - }, - child: widget.child, + return Stack( + children: [ + NotificationListener( + onNotification: (notification) => + _handleNewMetrics(notification.metrics), + child: NotificationListener( + 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; @@ -188,7 +184,7 @@ class _ScrollShadowState extends State { 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 diff --git a/pubspec.yaml b/pubspec.yaml index 4c81aaf..a7af454 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_scroll_shadow description: ScrollShadow adds shadows to a scrollable child. Supports ScrollController and vertical or horizontal orientation. -version: 1.2.5 +version: 1.2.6 repository: https://github.com/rickypid/flutter_scroll_shadow issue_tracker: https://github.com/rickypid/flutter_scroll_shadow/issues homepage: https://github.com/rickypid/flutter_scroll_shadow @@ -15,9 +15,9 @@ dependencies: sdk: flutter dev_dependencies: + collection: ^1.18.0 flutter_lints: ^5.0.0 flutter_test: sdk: flutter - collection: ^1.18.0 flutter: null \ No newline at end of file diff --git a/test/both_axis_test.dart b/test/both_axis_test.dart index 5a37a48..880ee4a 100644 --- a/test/both_axis_test.dart +++ b/test/both_axis_test.dart @@ -1,7 +1,7 @@ import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_scroll_shadow/flutter_scroll_shadow.dart'; +import 'package:flutter_test/flutter_test.dart'; const _verticalShadowSize = 40.0; const _verticalShadowColor = Colors.pink; @@ -13,23 +13,24 @@ class _BothAxisShadow extends StatelessWidget { const _BothAxisShadow(); @override - Widget build(BuildContext context) { - return MaterialApp( + Widget build(BuildContext context) => MaterialApp( home: Scaffold( - body: Center( - // Constraint the app size to be sure to have scroll shadows - child: SizedBox( - height: 300, - width: 300, - child: ScrollShadow( - size: _verticalShadowSize, - color: _verticalShadowColor, - child: ListView.builder( - itemBuilder: (context, rowIndex) => _MyRow(rowIndex))), + body: Center( + // Constraint the app size to be sure to have scroll shadows + child: SizedBox( + height: 300, + width: 300, + child: ScrollShadow( + size: _verticalShadowSize, + color: _verticalShadowColor, + child: ListView.builder( + itemBuilder: (context, rowIndex) => _MyRow(rowIndex), + ), + ), + ), + ), ), - ), - )); - } + ); } class _MyRow extends StatelessWidget { @@ -39,46 +40,45 @@ class _MyRow extends StatelessWidget { final controller = ScrollController(); @override - Widget build(BuildContext context) { - return Card( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - children: [ - Text( - 'Row $rowIndex', - style: const TextStyle(fontWeight: FontWeight.bold), - ), - ScrollShadow( - size: _horizontalShadowSize, - color: _horizontalShadowColor, - child: Scrollbar( - scrollbarOrientation: ScrollbarOrientation.bottom, - thumbVisibility: true, - trackVisibility: true, - controller: controller, - child: SingleChildScrollView( + Widget build(BuildContext context) => Card( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + children: [ + Text( + 'Row $rowIndex', + style: const TextStyle(fontWeight: FontWeight.bold), + ), + ScrollShadow( + size: _horizontalShadowSize, + color: _horizontalShadowColor, + child: Scrollbar( + scrollbarOrientation: ScrollbarOrientation.bottom, + thumbVisibility: true, + trackVisibility: true, controller: controller, - scrollDirection: Axis.horizontal, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - children: List.generate( + child: SingleChildScrollView( + controller: controller, + scrollDirection: Axis.horizontal, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + children: List.generate( 20, (columnIndex) => Padding( - padding: const EdgeInsets.all(8.0), - child: Text('R${rowIndex}C$columnIndex'), - )), + padding: const EdgeInsets.all(8.0), + child: Text('R${rowIndex}C$columnIndex'), + ), + ), + ), ), ), ), ), - ), - ], + ], + ), ), - ), - ); - } + ); } enum _Direction { @@ -105,11 +105,15 @@ AnimatedOpacity _findVerticalShadow(_Direction direction) { expect(gradient.begin, Alignment.bottomCenter); expect(gradient.end, Alignment.topCenter); - if (const ListEquality().equals(gradient.colors, - [_verticalShadowColor.withOpacity(0), _verticalShadowColor])) { + if (const ListEquality().equals( + gradient.colors, + [_verticalShadowColor.withAlpha(0), _verticalShadowColor], + )) { return direction == _Direction.start; - } else if (const ListEquality().equals(gradient.colors, - [_verticalShadowColor, _verticalShadowColor.withOpacity(0)])) { + } else if (const ListEquality().equals( + gradient.colors, + [_verticalShadowColor, _verticalShadowColor.withAlpha(0)], + )) { return direction == _Direction.end; } else { fail('The gradient colors should be one of the above');