Skip to content

Commit

Permalink
Fix some warnings and replace deprecated items
Browse files Browse the repository at this point in the history
  • Loading branch information
Abestanis committed Jul 11, 2024
1 parent 2604533 commit f07bc54
Show file tree
Hide file tree
Showing 69 changed files with 442 additions and 538 deletions.
1 change: 1 addition & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// This library should be imported `as constants`
library;

export 'constants/constants.dart';
40 changes: 19 additions & 21 deletions lib/constants/theme/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ abstract class Theme {
//****************** Color scheme (preferable to colors) *********************
colorScheme: const ColorScheme(
brightness: Brightness.light,
background: Colors.white,
onBackground: AppColors.greyText,
primary: defaultPrimaryColor,
// This is not darker, though lighter version
primaryContainer: Color(0xff936bff),
onPrimary: Colors.white,
secondary: AppColors.eee,
secondaryContainer: Colors.white,
onSecondaryContainer: AppColors.greyText,
// todo: temporarily used for text in [AppButton], remove when ThemeExtensions are in place
onSecondary: defaultPrimaryColor,
error: Color(0xffed3b3b),
Expand Down Expand Up @@ -75,7 +74,7 @@ abstract class Theme {
),
textButtonTheme: TextButtonThemeData(
style: ButtonStyle(
textStyle: MaterialStateProperty.all(
textStyle: WidgetStateProperty.all(
const TextStyle(
color: defaultPrimaryColor,
fontFamily: 'Manrope',
Expand Down Expand Up @@ -141,21 +140,21 @@ abstract class Theme {
backgroundColor: Colors.white,
),
switchTheme: SwitchThemeData(
thumbColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor : null,
thumbColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor : null,
),
trackColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor.withAlpha(0x80) : null,
trackColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor.withAlpha(0x80) : null,
),
),
radioTheme: RadioThemeData(
fillColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor : null,
fillColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor : null,
),
),
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor : null,
fillColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor : null,
),
),
),
Expand All @@ -176,14 +175,13 @@ abstract class Theme {
//****************** Color scheme (preferable to colors) *********************
colorScheme: const ColorScheme(
brightness: Brightness.dark,
background: Colors.black,
onBackground: Colors.white,
primary: defaultPrimaryColor,
// This is not darker, though lighter version
primaryContainer: Color(0xff936bff),
onPrimary: Colors.white,
secondary: AppColors.grey,
secondaryContainer: Colors.black,
onSecondaryContainer: Colors.white,
// todo: temporarily used for text in [AppButton], remove when ThemeExtensions are in place
onSecondary: Colors.white,
error: Color(0xffed3b3b),
Expand Down Expand Up @@ -272,21 +270,21 @@ abstract class Theme {
backgroundColor: Color(0xff070707),
),
switchTheme: SwitchThemeData(
thumbColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor : null,
thumbColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor : null,
),
trackColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor.withAlpha(0x80) : null,
trackColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor.withAlpha(0x80) : null,
),
),
radioTheme: RadioThemeData(
fillColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor : null,
fillColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor : null,
),
),
checkboxTheme: CheckboxThemeData(
fillColor: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.selected) ? defaultPrimaryColor : null,
fillColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected) ? defaultPrimaryColor : null,
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/features/debug/debug_overlay_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DebugOverlayWidget extends ConsumerWidget {
padding: const EdgeInsets.all(20.0),
color: Colors.purpleAccent,
child: Container(
color: theme.colorScheme.background,
color: theme.colorScheme.secondaryContainer,
child: Stack(
children: [
Material(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PlayerInterfaceColorStyleControl extends Control {
_currentPalette.value = value;
_currentBackgroundColor.value = shadeColor(
-0.5,
value?.vibrantColor?.color ?? value?.dominantColor?.color ?? theme.colorScheme.background,
value?.vibrantColor?.color ?? value?.dominantColor?.color ?? theme.colorScheme.secondaryContainer,
);
}

Expand Down Expand Up @@ -110,7 +110,7 @@ class PlayerInterfaceColorStyleControl extends Control {

/// Allows to choose the [PlayerInterfaceColorStyle].
class PlayerInterfaceColorStyleSettingWidget extends StatelessWidget {
const PlayerInterfaceColorStyleSettingWidget({Key? key}) : super(key: key);
const PlayerInterfaceColorStyleSettingWidget({super.key});

@override
Widget build(BuildContext context) {
Expand All @@ -137,10 +137,10 @@ class PlayerInterfaceColorStyleSettingWidget extends StatelessWidget {
/// A shorthand builder for [Settings.playerInterfaceColorStyle].
class PlayerInterfaceColorStyleSettingBuilder extends StatelessWidget {
const PlayerInterfaceColorStyleSettingBuilder({
Key? key,
super.key,
required this.builder,
this.child,
}) : super(key: key);
});

final ValueWidgetBuilder<PlayerInterfaceColorStyle> builder;
final Widget? child;
Expand All @@ -157,9 +157,9 @@ class PlayerInterfaceColorStyleSettingBuilder extends StatelessWidget {

class PlayerInterfaceThemeOverride extends StatelessWidget {
const PlayerInterfaceThemeOverride({
Key? key,
super.key,
required this.child,
}) : super(key: key);
});

final Widget child;

Expand All @@ -172,8 +172,8 @@ class PlayerInterfaceThemeOverride extends StatelessWidget {
primary: Colors.white,
onSurface: Colors.white,
secondary: _shadeForSecondaryColor(backgroundColor),
onBackground: Colors.white,
background: backgroundColor,
onSecondaryContainer: Colors.white,
secondaryContainer: backgroundColor,
),
appBarTheme: theme.appBarTheme.copyWith(
color: _shadeForSecondaryColor(backgroundColor),
Expand Down Expand Up @@ -231,10 +231,10 @@ class PlayerInterfaceThemeOverride extends StatelessWidget {
/// A background to be used by [PlayerRoute].
class PlayerInterfaceColorWidget extends StatelessWidget {
const PlayerInterfaceColorWidget({
Key? key,
super.key,
this.child,
this.color,
}) : super(key: key);
});

final Widget? child;
final ValueGetter<Color?>? color;
Expand All @@ -253,7 +253,7 @@ class PlayerInterfaceColorWidget extends StatelessWidget {
);
case PlayerInterfaceColorStyle.themeBackgroundColor:
return Container(
color: color?.call() ?? theme.colorScheme.background,
color: color?.call() ?? theme.colorScheme.secondaryContainer,
child: child,
);
}
Expand All @@ -264,10 +264,9 @@ class PlayerInterfaceColorWidget extends StatelessWidget {

class _ArtColorWidget extends StatelessWidget {
const _ArtColorWidget({
Key? key,
required this.child,
required this.color,
}) : super(key: key);
});

final Widget? child;
final ValueGetter<Color?>? color;
Expand Down Expand Up @@ -295,9 +294,9 @@ class _ArtColorWidget extends StatelessWidget {
/// Provides a [ContentArt.onLoad] function.
class ContentArtLoadBuilder extends StatelessWidget {
const ContentArtLoadBuilder({
Key? key,
super.key,
required this.builder,
}) : super(key: key);
});

final Widget Function(ContentArtOnLoadCallback? onLoad) builder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ final textScaleFactorStateNotifierProvider = StateNotifierProvider<TextScaleFact
);

class TextScaleFactorStateNotifier extends StateNotifier<double> {
TextScaleFactorStateNotifier() : super(WidgetsBinding.instance.window.platformDispatcher.textScaleFactor);
TextScaleFactorStateNotifier() : super(WidgetsBinding.instance.platformDispatcher.textScaleFactor);

void setValue(double value) => state = value;
double get() => state;
Expand Down
4 changes: 1 addition & 3 deletions lib/localization/localization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AppLocalizations getl10n(BuildContext context) => AppLocalizations.of(context)!;
/// Gets [AppLocalizations] without context.
AppLocalizations get staticl10n {
try {
return lookupAppLocalizations(WidgetsBinding.instance.window.locale);
return lookupAppLocalizations(WidgetsBinding.instance.platformDispatcher.locale);
} catch (ex) {
// Load default locale.
return lookupAppLocalizations(const Locale('en', 'US'));
Expand Down Expand Up @@ -50,8 +50,6 @@ extension AppLocalizationsExtension on AppLocalizations {
}

String sortFeature<T extends Content>(ContentType<T> contentType, SortFeature<T> feature) {
// TODO: Remove ContentType cast, see https://github.com/dart-lang/language/issues/2315
// ignore: unnecessary_cast
switch (contentType as ContentType) {
case ContentType.song:
switch (feature as SongSortFeature) {
Expand Down
1 change: 1 addition & 0 deletions lib/logic/logic.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// This module contains all app logic classes.
library;

export 'models/models.dart';
export 'player/music_player.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/logic/models/album.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ class Album extends PersistentQueue implements PlatformAlbum {
artistId == null ? null : ContentControl.instance.state.artists.firstWhereOrNull((el) => el.id == artistId);

const Album({
required int id,
required super.id,
required this.album,
required this.albumArt,
required this.artist,
required this.artistId,
required this.firstYear,
required this.lastYear,
required this.numberOfSongs,
}) : super(id: id);
});

@override
AlbumCopyWith get copyWith => _AlbumCopyWith(this);
Expand Down
4 changes: 2 additions & 2 deletions lib/logic/models/playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class Playlist extends PersistentQueue with DuplicatingSongOriginMixin implement
}

Playlist({
required int id,
required super.id,
required this.filesystemPath,
required this.dateAdded,
required this.dateModified,
required this.name,
required this.songIds,
}) : super(id: id);
});

@override
PlaylistCopyWith get copyWith => _PlaylistCopyWith(this);
Expand Down
44 changes: 21 additions & 23 deletions lib/logic/models/sort.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import 'package:sweyer/sweyer.dart';

/// Interface for other sort feature enums.
abstract class SortFeature<T extends Content> extends Enum<String> {
const SortFeature._(String value) : super(value);
const SortFeature._(super.value);

/// Returns sort feature values for a given content.
static List<SortFeature<T>> getValuesForContent<T extends Content>(ContentType<T> contentType) {
// TODO: Remove ContentType cast, see https://github.com/dart-lang/language/issues/2315
// ignore: unnecessary_cast
switch (contentType as ContentType) {
case ContentType.song:
return SongSortFeature.values as List<SortFeature<T>>;
Expand All @@ -31,7 +29,7 @@ abstract class SortFeature<T extends Content> extends Enum<String> {
/// Each feature also has the default sort order - ASC or DESC.
/// When user changes the [SongSortFeature] the new default sort order is applied.
class SongSortFeature extends SortFeature<Song> {
const SongSortFeature._(String value) : super._(value);
const SongSortFeature._(super.value) : super._();

@override
bool get defaultOrderAscending => this != dateModified && this != dateAdded;
Expand Down Expand Up @@ -64,7 +62,7 @@ class SongSortFeature extends SortFeature<Song> {
/// Each feature also has the default sort order - ASC or DESC.
/// When user changes the [AlbumSortFeature] the new default sort order is applied.
class AlbumSortFeature extends SortFeature<Album> {
const AlbumSortFeature._(String value) : super._(value);
const AlbumSortFeature._(super.value) : super._();

@override
bool get defaultOrderAscending => this != year;
Expand Down Expand Up @@ -93,7 +91,7 @@ class AlbumSortFeature extends SortFeature<Album> {
/// Each feature also has the default sort order - ASC or DESC.
/// When user changes the [PlaylistSortFeature] the new default sort order is applied.
class PlaylistSortFeature extends SortFeature<Playlist> {
const PlaylistSortFeature._(String value) : super._(value);
const PlaylistSortFeature._(super.value) : super._();

@override
bool get defaultOrderAscending => this != dateModified && this != dateAdded;
Expand All @@ -118,7 +116,7 @@ class PlaylistSortFeature extends SortFeature<Playlist> {
/// Each feature also has the default sort order - ASC or DESC.
/// When user changes the [ArtistSortFeature] the new default sort order is applied.
class ArtistSortFeature extends SortFeature<Artist> {
const ArtistSortFeature._(String value) : super._(value);
const ArtistSortFeature._(super.value) : super._();

@override
bool get defaultOrderAscending => true;
Expand Down Expand Up @@ -164,10 +162,10 @@ abstract class Sort<T extends Content> extends Equatable {

class SongSort extends Sort<Song> {
const SongSort({
required SongSortFeature feature,
bool orderAscending = true,
}) : super(feature: feature, orderAscending: orderAscending);
SongSort.defaultOrder(feature) : super.defaultOrder(feature);
required SongSortFeature super.feature,
super.orderAscending = true,
});
SongSort.defaultOrder(super.feature) : super.defaultOrder();

factory SongSort.fromMap(Map map) => SongSort(
feature: EnumToString.fromString(
Expand Down Expand Up @@ -262,10 +260,10 @@ class SongSort extends Sort<Song> {

class AlbumSort extends Sort<Album> {
const AlbumSort({
required AlbumSortFeature feature,
bool orderAscending = true,
}) : super(feature: feature, orderAscending: orderAscending);
AlbumSort.defaultOrder(feature) : super.defaultOrder(feature);
required AlbumSortFeature super.feature,
super.orderAscending = true,
});
AlbumSort.defaultOrder(super.feature) : super.defaultOrder();

factory AlbumSort.fromMap(Map map) => AlbumSort(
feature: EnumToString.fromString(
Expand Down Expand Up @@ -357,10 +355,10 @@ class AlbumSort extends Sort<Album> {

class PlaylistSort extends Sort<Playlist> {
const PlaylistSort({
required PlaylistSortFeature feature,
bool orderAscending = true,
}) : super(feature: feature, orderAscending: orderAscending);
PlaylistSort.defaultOrder(feature) : super.defaultOrder(feature);
required PlaylistSortFeature super.feature,
super.orderAscending = true,
});
PlaylistSort.defaultOrder(super.feature) : super.defaultOrder();

factory PlaylistSort.fromMap(Map map) => PlaylistSort(
feature: EnumToString.fromString(
Expand Down Expand Up @@ -443,10 +441,10 @@ class PlaylistSort extends Sort<Playlist> {

class ArtistSort extends Sort<Artist> {
const ArtistSort({
required ArtistSortFeature feature,
bool orderAscending = true,
}) : super(feature: feature, orderAscending: orderAscending);
ArtistSort.defaultOrder(feature) : super.defaultOrder(feature);
required ArtistSortFeature super.feature,
super.orderAscending = true,
});
ArtistSort.defaultOrder(super.feature) : super.defaultOrder();

factory ArtistSort.fromMap(Map map) => ArtistSort(
feature: EnumToString.fromString(
Expand Down
Loading

0 comments on commit f07bc54

Please sign in to comment.