♻️ Replace the pattle_generator
This commit is contained in:
@@ -32,7 +32,7 @@ import 'package:island/widgets/content/cloud_files.dart';
|
||||
import 'package:island/widgets/content/markdown.dart';
|
||||
import 'package:island/widgets/safety/abuse_report_helper.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:palette_generator/palette_generator.dart';
|
||||
import 'package:island/services/color_extraction.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
@@ -581,14 +581,14 @@ Future<Color?> accountAppbarForcegroundColor(Ref ref, String uname) async {
|
||||
try {
|
||||
final account = await ref.watch(accountProvider(uname).future);
|
||||
if (account.profile.background == null) return null;
|
||||
final palette = await PaletteGenerator.fromImageProvider(
|
||||
final colors = await ColorExtractionService.getColorsFromImage(
|
||||
CloudImageWidget.provider(
|
||||
fileId: account.profile.background!.id,
|
||||
serverUrl: ref.watch(serverUrlProvider),
|
||||
),
|
||||
);
|
||||
final dominantColor = palette.dominantColor?.color;
|
||||
if (dominantColor == null) return null;
|
||||
if (colors.isEmpty) return null;
|
||||
final dominantColor = colors.first;
|
||||
return dominantColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
|
||||
} catch (_) {
|
||||
return null;
|
||||
|
@@ -21,7 +21,7 @@ import 'package:island/widgets/content/cloud_files.dart';
|
||||
import 'package:island/widgets/content/markdown.dart';
|
||||
import 'package:island/widgets/post/post_list.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:palette_generator/palette_generator.dart';
|
||||
import 'package:island/services/color_extraction.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
|
||||
@@ -278,14 +278,14 @@ Future<Color?> publisherAppbarForcegroundColor(Ref ref, String pubName) async {
|
||||
try {
|
||||
final publisher = await ref.watch(publisherProvider(pubName).future);
|
||||
if (publisher.background == null) return null;
|
||||
final palette = await PaletteGenerator.fromImageProvider(
|
||||
final colors = await ColorExtractionService.getColorsFromImage(
|
||||
CloudImageWidget.provider(
|
||||
fileId: publisher.background!.id,
|
||||
serverUrl: ref.watch(serverUrlProvider),
|
||||
),
|
||||
);
|
||||
final dominantColor = palette.dominantColor?.color;
|
||||
if (dominantColor == null) return null;
|
||||
if (colors.isEmpty) return null;
|
||||
final dominantColor = colors.first;
|
||||
return dominantColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
|
||||
} catch (_) {
|
||||
return null;
|
||||
|
@@ -8,7 +8,7 @@ import 'package:island/services/responsive.dart';
|
||||
import 'package:island/widgets/account/account_pfc.dart';
|
||||
import 'package:island/widgets/account/status.dart';
|
||||
import 'package:island/widgets/post/post_list.dart';
|
||||
import 'package:palette_generator/palette_generator.dart';
|
||||
import 'package:island/services/color_extraction.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -32,14 +32,14 @@ part 'realm_detail.g.dart';
|
||||
Future<Color?> realmAppbarForegroundColor(Ref ref, String realmSlug) async {
|
||||
final realm = await ref.watch(realmProvider(realmSlug).future);
|
||||
if (realm?.background == null) return null;
|
||||
final palette = await PaletteGenerator.fromImageProvider(
|
||||
final colors = await ColorExtractionService.getColorsFromImage(
|
||||
CloudImageWidget.provider(
|
||||
fileId: realm!.background!.id,
|
||||
serverUrl: ref.watch(serverUrlProvider),
|
||||
),
|
||||
);
|
||||
final dominantColor = palette.dominantColor?.color;
|
||||
if (dominantColor == null) return null;
|
||||
if (colors.isEmpty) return null;
|
||||
final dominantColor = colors.first;
|
||||
return dominantColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
|
||||
}
|
||||
|
||||
|
@@ -12,11 +12,11 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:island/pods/network.dart';
|
||||
import 'package:island/services/color_extraction.dart';
|
||||
import 'package:island/services/responsive.dart';
|
||||
import 'package:island/widgets/alert.dart';
|
||||
import 'package:island/widgets/app_scaffold.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:palette_generator/palette_generator.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:island/pods/config.dart';
|
||||
@@ -293,24 +293,26 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
trailing: const Icon(Symbols.chevron_right),
|
||||
onTap: () async {
|
||||
showLoadingModal(context);
|
||||
final palette = await PaletteGenerator.fromImageProvider(
|
||||
final colors = await ColorExtractionService.getColorsFromImage(
|
||||
FileImage(
|
||||
File('${docBasepath.value}/$kAppBackgroundImagePath'),
|
||||
),
|
||||
);
|
||||
if (palette.darkVibrantColor == null ||
|
||||
palette.lightVibrantColor == null) {
|
||||
if (colors.isEmpty) {
|
||||
if (context.mounted) hideLoadingModal(context);
|
||||
showErrorAlert(
|
||||
'Unable to calculate the domiant color of the background image.',
|
||||
'Unable to calculate the dominant color of the background image.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
final colorScheme = ColorScheme.fromSeed(
|
||||
seedColor: colors.first,
|
||||
);
|
||||
final color =
|
||||
MediaQuery.of(context).platformBrightness == Brightness.dark
|
||||
? palette.darkVibrantColor!.color
|
||||
: palette.lightVibrantColor!.color;
|
||||
? colorScheme.primary
|
||||
: colorScheme.primary;
|
||||
ref
|
||||
.read(appSettingsNotifierProvider.notifier)
|
||||
.setAppColorScheme(color.value);
|
||||
|
Reference in New Issue
Block a user