Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): migrate to Flutter 3.24.2 #58

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
18 changes: 10 additions & 8 deletions lib/helper/command_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ List<String> _defaultData(final Object fromObject, final String command) {
throw Exception('Unexpected fromObject type');
}

return parseCommand(command,
url: url,
title: title,
description: description,
type: type,
preview: preview,
thumbnail: thumbnail,
icon: icon);
return parseCommand(
command,
url: url,
title: title,
description: description,
type: type,
preview: preview,
thumbnail: thumbnail,
icon: icon,
);
}

Future<void> playFromUrl(
Expand Down
3 changes: 2 additions & 1 deletion lib/helper/time.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// Used to calculate YouTube video age
/// Returns [String]
/// ```dart
/// timeSince(DateTime., DateTime.now());
/// start =
/// print(timeSince(DateTime(2022), DateTime(2023)); // 1 year
/// ```
String timeSince(final DateTime startTime, final DateTime endTime) {
final duration = startTime.difference(endTime);
Expand Down
27 changes: 13 additions & 14 deletions lib/model/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:yaml/yaml.dart';
import 'package:yaml_edit/yaml_edit.dart';

import '../const.dart';
import '../util/dynamic.dart';
import 'setting_options.dart';

abstract class YamlConfig {
Expand Down Expand Up @@ -82,25 +83,22 @@ class UserConfig extends YamlConfig {
required final String rawFile,
required final dynamic json,
}) {
if (!(json is Map)) {
if (json is! Map<String, Object>) {
return UserConfig._defaultConfig();
}

final minimizedOnLaunch = switch (json['minimizedOnLaunch']) {
final bool value => value,
_ => null
};
final minimizedOnLaunch = json['minimizedOnLaunch']?.unwrapOrNull<bool>();

final onPlay = switch (json['onPlay']) {
'nothing' => OnPlayOptions.nothing,
'minimize' => OnPlayOptions.minimize,
'tray' => OnPlayOptions.tray,
'exit' => OnPlayOptions.exit,
_ => null
};
final autofocusNavigation = switch (json['autofocusNavigation']) {
final bool value => value,
_ => null
};
final autofocusNavigation =
json['autofocusNavigation']?.unwrapOrNull<bool>();

final videoPlayCommand = switch (json['videoPlayCommand']) {
final List<dynamic> value =>
value.map((final command) => command.toString()).toList(),
Expand All @@ -111,10 +109,11 @@ class UserConfig extends YamlConfig {
value.map((final command) => command.toString()).toList(),
_ => null
};
final youtube = switch (json['youtube']) {
final Map<dynamic, dynamic>? value => value,
_ => null
};
final youtube = json['youtube']?.unwrapOrNull<Map<Object, Object>>();
// final youtube = switch (json['youtube']) {
// final Map<dynamic, dynamic>? value => value,
// _ => null
// };
final theme = switch (json['theme']) {
final Map<dynamic, dynamic>? value => value,
_ => null
Expand Down Expand Up @@ -224,7 +223,7 @@ class _ConfigYoutube extends YamlConfig {
factory _ConfigYoutube.fromMap({
required final String filePath,
required final String rawFile,
final Map<dynamic, dynamic>? youtube,
final Map<Object, Object>? youtube,
}) =>
youtube == null
? _ConfigYoutube(apiKey: '')
Expand Down
47 changes: 21 additions & 26 deletions lib/model/setting_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ enum OnPlayOptions implements SettingOptions {
@override
int currentIndex() => super.index;

factory OnPlayOptions.fromString(final String option) {
return switch (option) {
'nothing' => OnPlayOptions.nothing,
'minimize' => OnPlayOptions.minimize,
'tray' => OnPlayOptions.tray,
'exit' => OnPlayOptions.exit,
_ => OnPlayOptions.nothing,
};
}
factory OnPlayOptions.fromString(final String option) => switch (option) {
'nothing' => OnPlayOptions.nothing,
'minimize' => OnPlayOptions.minimize,
'tray' => OnPlayOptions.tray,
'exit' => OnPlayOptions.exit,
_ => OnPlayOptions.nothing,
};
}

/// Theme brightness mode.
Expand All @@ -61,14 +59,12 @@ enum BrightnessOptions implements SettingOptions {
@override
int currentIndex() => super.index;

factory BrightnessOptions.fromString(final String option) {
return switch (option) {
'light' => BrightnessOptions.light,
'dark' => BrightnessOptions.dark,
'system' => BrightnessOptions.system,
_ => BrightnessOptions.dark,
};
}
factory BrightnessOptions.fromString(final String option) => switch (option) {
'light' => BrightnessOptions.light,
'dark' => BrightnessOptions.dark,
'system' => BrightnessOptions.system,
_ => BrightnessOptions.dark,
};
}

/// Visual desity mode controls how dense the UI looks. The densier the UI is,
Expand All @@ -94,13 +90,12 @@ enum VisualDensityOptions implements SettingOptions {
@override
int currentIndex() => super.index;

factory VisualDensityOptions.fromString(final String option) {
return switch (option) {
'compact' => VisualDensityOptions.compact,
'standard' => VisualDensityOptions.standard,
'comfort' => VisualDensityOptions.comfort,
'adaptive' => VisualDensityOptions.adaptive,
_ => VisualDensityOptions.adaptive,
};
}
factory VisualDensityOptions.fromString(final String option) =>
switch (option) {
'compact' => VisualDensityOptions.compact,
'standard' => VisualDensityOptions.standard,
'comfort' => VisualDensityOptions.comfort,
'adaptive' => VisualDensityOptions.adaptive,
_ => VisualDensityOptions.adaptive,
};
}
99 changes: 51 additions & 48 deletions lib/model/theme.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import 'dart:ui';

class AppTheme {
final Brightness brightness;
final Color background;
final Color backgroundHighlight;
final Color backgroundDarker;
final Color text;
final Color primary;

const AppTheme({
required this.brightness,
required this.background,
Expand All @@ -17,45 +10,55 @@ class AppTheme {
required this.primary,
});

factory AppTheme.arc() {
return const AppTheme(
brightness: Brightness.light,
background: Color(0xFFFFFFFF),
backgroundHighlight: Color(0xFFFAFBFC),
backgroundDarker: Color(0xFFF5F6F7),
text: Color(0xFFD3DAE3),
primary: Color(0xFF5294E2),
);
}

factory AppTheme.arcDarker() {
return const AppTheme(
brightness: Brightness.light,
background: Color(0xFF404552),
backgroundHighlight: Color(0xFF505666),
backgroundDarker: Color(0xFF2F343F),
text: Color(0xFFD3DAE3),
primary: Color(0xFF5294E2),
);
}

factory AppTheme.arcDark() {
return const AppTheme(
brightness: Brightness.dark,
background: Color(0xFF404552),
backgroundHighlight: Color(0xFF505666),
backgroundDarker: Color(0xFF2F343F),
text: Color(0xFFD3DAE3),
primary: Color(0xFF5294E2),
);
}

factory AppTheme.from(final String themeName) {
return switch (themeName) {
'Arc' => AppTheme.arc(),
'Arc-Darker' => AppTheme.arcDarker(),
'Arc-Dark' => AppTheme.arcDark(),
_ => AppTheme.arcDark(),
};
}
///
final Brightness brightness;

///
final Color background;

///
final Color backgroundHighlight;

///
final Color backgroundDarker;

///
final Color text;

///
final Color primary;

factory AppTheme.arc() => const AppTheme(
brightness: Brightness.light,
background: Color(0xFFFFFFFF),
backgroundHighlight: Color(0xFFFAFBFC),
backgroundDarker: Color(0xFFF5F6F7),
text: Color(0xFFD3DAE3),
primary: Color(0xFF5294E2),
);

factory AppTheme.arcDarker() => const AppTheme(
brightness: Brightness.light,
background: Color(0xFF404552),
backgroundHighlight: Color(0xFF505666),
backgroundDarker: Color(0xFF2F343F),
text: Color(0xFFD3DAE3),
primary: Color(0xFF5294E2),
);

factory AppTheme.arcDark() => const AppTheme(
brightness: Brightness.dark,
background: Color(0xFF404552),
backgroundHighlight: Color(0xFF505666),
backgroundDarker: Color(0xFF2F343F),
text: Color(0xFFD3DAE3),
primary: Color(0xFF5294E2),
);

factory AppTheme.from(final String themeName) => switch (themeName) {
'Arc' => AppTheme.arc(),
'Arc-Darker' => AppTheme.arcDarker(),
'Arc-Dark' => AppTheme.arcDark(),
_ => AppTheme.arcDark(),
};
}
17 changes: 6 additions & 11 deletions lib/page/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,17 @@ class SettingsPage extends StatelessWidget {
return const Center(child: ProgressBar());
}

final userConfig = switch (data.first) {
final UserConfig userConfig => userConfig,
_ => null,
};
final feedList = switch (data.last) {
final String feedList => feedList,
_ => null,
};
final userConfig = data.first;
final feedList = data.last;

if (userConfig == null || feedList == null) {
if (userConfig is! UserConfig || feedList is! String) {
return const SizedBox();
}

final parsedFeedList = switch (yaml.loadYaml(feedList)) {
final List<dynamic> urls =>
urls.map((final url) => url.toString()).toList(),
final List<dynamic> urls => [
for (final url in urls) url.toString()
],
_ => ['']
};

Expand Down
8 changes: 8 additions & 0 deletions lib/util/dynamic.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extension Unwrap on Object {
/// TODO:
///
T? unwrapOrNull<T>([final T Function(T)? callback]) => switch (this) {
final T value => callback == null ? value : callback(value),
_ => null,
};
}
4 changes: 1 addition & 3 deletions lib/widget/search_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class SearchError extends StatelessWidget {
message: 'Copy to clipboard',
child: Button(
child: const Icon(FluentIcons.copy),
onPressed: () async {
await _handleCopyToClipboard(context);
},
onPressed: () async => _handleCopyToClipboard(context),
),
),
),
Expand Down
Loading
Loading