Skip to content

Commit

Permalink
refactor: Update PlayxThemeAnimation to be a sealed class - CU-86c0287m8
Browse files Browse the repository at this point in the history
- Specific types of animations are represented by subclasses such as PlayxThemeClipperAnimation, PlayxThemeFadeAnimation, etc.
- Move animation specific properties to it's class.
- Update PlayxTheme update methods to include animation.
- If [animation] is `null`, the theme will change instantly. If [animation] is provided,
- the theme change will be animated according to the type of animation specified.
  • Loading branch information
basemosama committed Aug 22, 2024
1 parent 9d09359 commit a3c3d1d
Show file tree
Hide file tree
Showing 13 changed files with 761 additions and 538 deletions.
34 changes: 15 additions & 19 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ class HomeScreen extends StatelessWidget {
.supportedThemes[index]
.id,
animation:
const PlayxThemeAnimation(
clipper:
ThemeSwitcherBoxClipper(),
));
const PlayxThemeAnimation
.horizontalSlide());
},
),
)),
Expand All @@ -133,21 +131,18 @@ class HomeScreen extends StatelessWidget {
),
),
),
PlayxThemeSwitcher(
builder: (ctx, theme) => ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: PlayxColors.of(context).primaryContainer,
),
onPressed: () {
PlayxTheme.next(
context: ctx,
animation: const PlayxThemeAnimation(
duration: Duration(milliseconds: 500),
type: PlayxThemeAnimationType.fade),
);
},
child: const Text('Next Theme'),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: PlayxColors.of(context).primaryContainer,
),
onPressed: () {
PlayxTheme.next(
animation: const PlayxThemeAnimation.fade(
duration: Duration(milliseconds: 500),
),
);
},
child: const Text('Next Theme'),
),
],
),
Expand All @@ -156,7 +151,8 @@ class HomeScreen extends StatelessWidget {
builder: (ctx, theme) => FloatingActionButton(
onPressed: () {
PlayxTheme.next(
context: ctx,
animation: PlayxThemeAnimation.clipper(
clipper: const ThemeSwitcherCircleClipper(), context: ctx),
);
},
tooltip: 'Next Theme',
Expand Down
1 change: 0 additions & 1 deletion lib/playx_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export 'package:playx_core/playx_core.dart';
export 'src/config/config.dart';
export 'src/model/playx_colors.dart';
export 'src/model/playx_theme_animation.dart';
export 'src/model/playx_theme_animation_type.dart';
export 'src/model/x_theme.dart';
export 'src/playx_theme.dart';
export 'src/utils/build_context_extension.dart';
Expand Down
15 changes: 11 additions & 4 deletions lib/src/config/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import 'package:flutter/material.dart';
import 'package:playx_theme/playx_theme.dart';

/// Theme config :
/// used to configure out app theme by providing the app with the needed themes.
/// Create a class that extends the [PlayxThemeConfig] class to implement your own themes.
/// defaults to [XDefaultThemeConfig].
/// Used to configure the app's theme by specifying the available themes,
/// the initial theme index, and whether to save the selected theme to device storage.
class PlayxThemeConfig {
/// Index of the initial theme to start the app with.
final int initialThemeIndex;
Expand All @@ -16,8 +15,13 @@ class PlayxThemeConfig {
/// List of themes to use in the app.
List<XTheme> themes;

/// Whether to migrate preferences to asynchronous preferences.
final bool migratePrefsToAsyncPrefs;

/// Creates a [PlayxThemeConfig] instance.
///
/// The [initialThemeIndex] must be non-negative and less than the length of [themes].
/// The [themes] list must not be empty.
PlayxThemeConfig({
this.initialThemeIndex = 0,
this.saveTheme = true,
Expand All @@ -27,8 +31,11 @@ class PlayxThemeConfig {
assert(themes.isNotEmpty);
}

///Default theme configuration.
/// Default theme configuration.
class XDefaultThemeConfig extends PlayxThemeConfig {
/// Creates a default [XDefaultThemeConfig] instance with predefined light and dark themes.
///
/// The initial theme is determined based on the device's current theme mode.
XDefaultThemeConfig()
: super(themes: [
XTheme(
Expand Down
Loading

0 comments on commit a3c3d1d

Please sign in to comment.