Skip to content

Commit d8b4036

Browse files
committed
Added withOpacityCompact extension to ensure compatibility with Flutter versions below 3.27.
1 parent d5d66ea commit d8b4036

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:flutter/material.dart';
2+
3+
extension ColorCompatExtensions on Color {
4+
/// Returns a new color that matches this color with the given opacity.
5+
///
6+
/// This is a compatibility layer that ensures compatibility with Flutter
7+
/// versions below 3.27. In Flutter 3.27 and later, `Color.withOpacity`
8+
/// has been deprecated in favor of `Color.withValues`.
9+
///
10+
/// This method bridges the gap by providing a consistent way to adjust
11+
/// the opacity of a color across different Flutter versions.
12+
///
13+
/// **Important:** Once the minimum supported Flutter version is bumped
14+
/// to 3.27 or higher, this method should be removed and replaced with
15+
/// `withValues(alpha: opacity)`.
16+
///
17+
/// See also:
18+
/// * [Color.withOpacity], which is deprecated in Flutter 3.27 and later.
19+
/// * [Color.withValues], the recommended replacement for `withOpacity`.
20+
Color withOpacityCompat(double opacity) {
21+
// Compatibility layer that uses the legacy withOpacity method, while
22+
// ignoring the deprecation for now (in order to guarantee N-1 minimum
23+
// version compatibility).
24+
// Once it's removed from a future update, we'll have to replace uses of
25+
// this method with withValues(alpha: opacity).
26+
// TODO: Replace this bridge method once the above holds true.
27+
//ignore: deprecated_member_use
28+
return withOpacity(opacity);
29+
}
30+
}

lib/src/material/material_controls.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:chewie/src/center_seek_button.dart';
55
import 'package:chewie/src/chewie_player.dart';
66
import 'package:chewie/src/chewie_progress_colors.dart';
77
import 'package:chewie/src/helpers/utils.dart';
8+
import 'package:chewie/src/material/color_compat_extensions.dart';
89
import 'package:chewie/src/material/material_progress_bar.dart';
910
import 'package:chewie/src/material/widgets/options_dialog.dart';
1011
import 'package:chewie/src/material/widgets/playback_speed_dialog.dart';
@@ -470,7 +471,7 @@ class _MaterialControlsState extends State<MaterialControls>
470471
text: '/ ${formatDuration(duration)}',
471472
style: TextStyle(
472473
fontSize: 14.0,
473-
color: Colors.white.withValues(alpha: .75),
474+
color: Colors.white.withOpacityCompat(.75),
474475
fontWeight: FontWeight.normal,
475476
),
476477
)
@@ -683,9 +684,9 @@ class _MaterialControlsState extends State<MaterialControls>
683684
playedColor: Theme.of(context).colorScheme.secondary,
684685
handleColor: Theme.of(context).colorScheme.secondary,
685686
bufferedColor:
686-
Theme.of(context).colorScheme.surface.withValues(alpha: 0.5),
687+
Theme.of(context).colorScheme.surface.withOpacityCompat(0.5),
687688
backgroundColor:
688-
Theme.of(context).disabledColor.withValues(alpha: .5),
689+
Theme.of(context).disabledColor.withOpacityCompat(.5),
689690
),
690691
draggableProgressBar: chewieController.draggableProgressBar,
691692
),

lib/src/material/material_desktop_controls.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:chewie/src/center_play_button.dart';
55
import 'package:chewie/src/chewie_player.dart';
66
import 'package:chewie/src/chewie_progress_colors.dart';
77
import 'package:chewie/src/helpers/utils.dart';
8+
import 'package:chewie/src/material/color_compat_extensions.dart';
89
import 'package:chewie/src/material/material_progress_bar.dart';
910
import 'package:chewie/src/material/widgets/options_dialog.dart';
1011
import 'package:chewie/src/material/widgets/playback_speed_dialog.dart';
@@ -649,9 +650,9 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
649650
playedColor: Theme.of(context).colorScheme.secondary,
650651
handleColor: Theme.of(context).colorScheme.secondary,
651652
bufferedColor:
652-
Theme.of(context).colorScheme.surface.withValues(alpha: 0.5),
653+
Theme.of(context).colorScheme.surface.withOpacityCompat(0.5),
653654
backgroundColor:
654-
Theme.of(context).disabledColor.withValues(alpha: 0.5),
655+
Theme.of(context).disabledColor.withOpacityCompat(0.5),
655656
),
656657
draggableProgressBar: chewieController.draggableProgressBar,
657658
),

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ homepage: https://github.com/fluttercommunity/chewie
55

66
environment:
77
sdk: '>=3.3.0 <4.0.0'
8-
flutter: ">=3.27.0"
8+
flutter: ">=3.24.0"
99

1010
dependencies:
1111
cupertino_icons: ^1.0.5

0 commit comments

Comments
 (0)