mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-04-19 20:59:36 +00:00
格式化代码
This commit is contained in:
parent
94f1376572
commit
de8b0bc066
5 changed files with 65 additions and 30 deletions
|
|
@ -62,8 +62,8 @@ class MySearchBar extends HookConsumerWidget {
|
||||||
currentQuery = query;
|
currentQuery = query;
|
||||||
|
|
||||||
// In a real application, there should be some error handling here.
|
// In a real application, there should be some error handling here.
|
||||||
final options =
|
final options = await api.libraries
|
||||||
await api.libraries.search(libraryId: settings.activeLibraryId!, query: query, limit: 3);
|
.search(libraryId: settings.activeLibraryId!, query: query, limit: 3);
|
||||||
|
|
||||||
// If another search happened after this one, throw away these options.
|
// If another search happened after this one, throw away these options.
|
||||||
if (currentQuery != query) {
|
if (currentQuery != query) {
|
||||||
|
|
@ -82,7 +82,8 @@ class MySearchBar extends HookConsumerWidget {
|
||||||
dividerColor: Colors.transparent,
|
dividerColor: Colors.transparent,
|
||||||
builder: (context, controller) {
|
builder: (context, controller) {
|
||||||
return SearchBar(
|
return SearchBar(
|
||||||
constraints: const BoxConstraints(minWidth: 360.0, maxWidth: 1050.0, minHeight: 56.0),
|
constraints: const BoxConstraints(
|
||||||
|
minWidth: 360.0, maxWidth: 1050.0, minHeight: 56.0),
|
||||||
controller: controller,
|
controller: controller,
|
||||||
focusNode: searchBarFocusNode,
|
focusNode: searchBarFocusNode,
|
||||||
// "What's your next page-turner?"
|
// "What's your next page-turner?"
|
||||||
|
|
@ -99,7 +100,10 @@ class MySearchBar extends HookConsumerWidget {
|
||||||
// opacity: 0.5 for the hint text
|
// opacity: 0.5 for the hint text
|
||||||
hintStyle: WidgetStatePropertyAll(
|
hintStyle: WidgetStatePropertyAll(
|
||||||
Theme.of(context).textTheme.bodyMedium!.copyWith(
|
Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.5),
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onSurface
|
||||||
|
.withValues(alpha: 0.5),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
textInputAction: TextInputAction.search,
|
textInputAction: TextInputAction.search,
|
||||||
|
|
@ -232,8 +236,9 @@ class BookSearchResultMini extends HookConsumerWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final item = ref.watch(libraryItemProvider(book.libraryItemId)).valueOrNull;
|
final item = ref.watch(libraryItemProvider(book.libraryItemId)).valueOrNull;
|
||||||
final image =
|
final image = item == null
|
||||||
item == null ? const AsyncValue.loading() : ref.watch(coverImageProvider(item.id));
|
? const AsyncValue.loading()
|
||||||
|
: ref.watch(coverImageProvider(item.id));
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: SizedBox(
|
leading: SizedBox(
|
||||||
width: 50,
|
width: 50,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
if (currentBook == null) {
|
if (currentBook == null) {
|
||||||
return const SizedBox.shrink();
|
return const SizedBox.shrink();
|
||||||
}
|
}
|
||||||
final itemBeingPlayed = ref.watch(libraryItemProvider(currentBook.libraryItemId));
|
final itemBeingPlayed =
|
||||||
|
ref.watch(libraryItemProvider(currentBook.libraryItemId));
|
||||||
final player = ref.watch(audiobookPlayerProvider);
|
final player = ref.watch(audiobookPlayerProvider);
|
||||||
final imageOfItemBeingPlayed = itemBeingPlayed.valueOrNull != null
|
final imageOfItemBeingPlayed = itemBeingPlayed.valueOrNull != null
|
||||||
? ref.watch(
|
? ref.watch(
|
||||||
|
|
@ -64,7 +65,8 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
themeOfLibraryItemProvider(
|
themeOfLibraryItemProvider(
|
||||||
itemBeingPlayed.valueOrNull?.id,
|
itemBeingPlayed.valueOrNull?.id,
|
||||||
brightness: Theme.of(context).brightness,
|
brightness: Theme.of(context).brightness,
|
||||||
highContrast: appSettings.themeSettings.highContrast || MediaQuery.of(context).highContrast,
|
highContrast: appSettings.themeSettings.highContrast ||
|
||||||
|
MediaQuery.of(context).highContrast,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -86,7 +88,8 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
onDragDown: (percentage) async {
|
onDragDown: (percentage) async {
|
||||||
// preferred volume
|
// preferred volume
|
||||||
// set volume to 0 when dragging down
|
// set volume to 0 when dragging down
|
||||||
await player.setVolume(preferredVolume * (1 - percentage.clamp(0, .75)));
|
await player
|
||||||
|
.setVolume(preferredVolume * (1 - percentage.clamp(0, .75)));
|
||||||
},
|
},
|
||||||
minHeight: playerMinHeight,
|
minHeight: playerMinHeight,
|
||||||
// subtract the height of notches and other system UI
|
// subtract the height of notches and other system UI
|
||||||
|
|
@ -106,8 +109,10 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
// at what point should the player switch from miniplayer to expanded player
|
// at what point should the player switch from miniplayer to expanded player
|
||||||
// also at this point the image should be at its max size and in the center of the player
|
// also at this point the image should be at its max size and in the center of the player
|
||||||
final miniplayerPercentageDeclaration =
|
final miniplayerPercentageDeclaration =
|
||||||
(maxImgSize - playerMinHeight) / (playerMaxHeight - playerMinHeight);
|
(maxImgSize - playerMinHeight) /
|
||||||
final bool isFormMiniplayer = percentage < miniplayerPercentageDeclaration;
|
(playerMaxHeight - playerMinHeight);
|
||||||
|
final bool isFormMiniplayer =
|
||||||
|
percentage < miniplayerPercentageDeclaration;
|
||||||
|
|
||||||
if (!isFormMiniplayer) {
|
if (!isFormMiniplayer) {
|
||||||
// this calculation needs a refactor
|
// this calculation needs a refactor
|
||||||
|
|
@ -207,14 +212,17 @@ class AudiobookChapterProgressBar extends HookConsumerWidget {
|
||||||
|
|
||||||
// now find the chapter that corresponds to the current time
|
// now find the chapter that corresponds to the current time
|
||||||
// and calculate the progress of the current chapter
|
// and calculate the progress of the current chapter
|
||||||
final currentChapterProgress =
|
final currentChapterProgress = currentChapter == null
|
||||||
currentChapter == null ? null : (player.positionInBook - currentChapter.start);
|
? null
|
||||||
|
: (player.positionInBook - currentChapter.start);
|
||||||
|
|
||||||
final currentChapterBuffered =
|
final currentChapterBuffered = currentChapter == null
|
||||||
currentChapter == null ? null : (player.bufferedPositionInBook - currentChapter.start);
|
? null
|
||||||
|
: (player.bufferedPositionInBook - currentChapter.start);
|
||||||
|
|
||||||
return ProgressBar(
|
return ProgressBar(
|
||||||
progress: currentChapterProgress ?? position.data ?? const Duration(seconds: 0),
|
progress:
|
||||||
|
currentChapterProgress ?? position.data ?? const Duration(seconds: 0),
|
||||||
total: currentChapter == null
|
total: currentChapter == null
|
||||||
? player.book?.duration ?? const Duration(seconds: 0)
|
? player.book?.duration ?? const Duration(seconds: 0)
|
||||||
: currentChapter.end - currentChapter.start,
|
: currentChapter.end - currentChapter.start,
|
||||||
|
|
@ -226,7 +234,8 @@ class AudiobookChapterProgressBar extends HookConsumerWidget {
|
||||||
player.seek(duration);
|
player.seek(duration);
|
||||||
},
|
},
|
||||||
thumbRadius: 8,
|
thumbRadius: 8,
|
||||||
buffered: currentChapterBuffered ?? buffered.data ?? const Duration(seconds: 0),
|
buffered:
|
||||||
|
currentChapterBuffered ?? buffered.data ?? const Duration(seconds: 0),
|
||||||
bufferedBarColor: Theme.of(context).colorScheme.secondary,
|
bufferedBarColor: Theme.of(context).colorScheme.secondary,
|
||||||
timeLabelType: TimeLabelType.remainingTime,
|
timeLabelType: TimeLabelType.remainingTime,
|
||||||
timeLabelLocation: TimeLabelLocation.below,
|
timeLabelLocation: TimeLabelLocation.below,
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,10 @@ class PlayerWhenExpanded extends HookConsumerWidget {
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Theme.of(context).colorScheme.primary.withValues(alpha: 0.1),
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.primary
|
||||||
|
.withValues(alpha: 0.1),
|
||||||
blurRadius: 32 * earlyPercentage,
|
blurRadius: 32 * earlyPercentage,
|
||||||
spreadRadius: 8 * earlyPercentage,
|
spreadRadius: 8 * earlyPercentage,
|
||||||
// offset: Offset(0, 16 * earlyPercentage),
|
// offset: Offset(0, 16 * earlyPercentage),
|
||||||
|
|
@ -171,7 +174,10 @@ class PlayerWhenExpanded extends HookConsumerWidget {
|
||||||
currentBookMetadata?.authorName ?? '',
|
currentBookMetadata?.authorName ?? '',
|
||||||
].join(' - '),
|
].join(' - '),
|
||||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||||
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7),
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onSurface
|
||||||
|
.withValues(alpha: 0.7),
|
||||||
),
|
),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ class PlayerWhenMinimized extends HookConsumerWidget {
|
||||||
final vanishingPercentage = 1 - percentageMiniplayer;
|
final vanishingPercentage = 1 - percentageMiniplayer;
|
||||||
// final progress =
|
// final progress =
|
||||||
// useStream(player.slowPositionStreamInBook, initialData: Duration.zero);
|
// useStream(player.slowPositionStreamInBook, initialData: Duration.zero);
|
||||||
final progress = useStream(player.positionStream, initialData: Duration.zero);
|
final progress =
|
||||||
|
useStream(player.positionStream, initialData: Duration.zero);
|
||||||
|
|
||||||
final bookMetaExpanded = ref.watch(currentBookMetadataProvider);
|
final bookMetaExpanded = ref.watch(currentBookMetadataProvider);
|
||||||
|
|
||||||
|
|
@ -58,7 +59,8 @@ class PlayerWhenMinimized extends HookConsumerWidget {
|
||||||
context.pushNamed(
|
context.pushNamed(
|
||||||
Routes.libraryItem.name,
|
Routes.libraryItem.name,
|
||||||
pathParameters: {
|
pathParameters: {
|
||||||
Routes.libraryItem.pathParamName!: player.book!.libraryItemId,
|
Routes.libraryItem.pathParamName!:
|
||||||
|
player.book!.libraryItemId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -92,7 +94,10 @@ class PlayerWhenMinimized extends HookConsumerWidget {
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.7),
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onSurface
|
||||||
|
.withValues(alpha: 0.7),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
@ -138,7 +143,8 @@ class PlayerWhenMinimized extends HookConsumerWidget {
|
||||||
child: LinearProgressIndicator(
|
child: LinearProgressIndicator(
|
||||||
// value: (progress.data ?? Duration.zero).inSeconds /
|
// value: (progress.data ?? Duration.zero).inSeconds /
|
||||||
// player.book!.duration.inSeconds,
|
// player.book!.duration.inSeconds,
|
||||||
value: (progress.data ?? Duration.zero).inSeconds / player.duration!.inSeconds,
|
value: (progress.data ?? Duration.zero).inSeconds /
|
||||||
|
player.duration!.inSeconds,
|
||||||
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
color: Theme.of(context).colorScheme.onPrimaryContainer,
|
||||||
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,8 @@ class ScaffoldWithNavBar extends HookConsumerWidget {
|
||||||
// extended: false,
|
// extended: false,
|
||||||
destinations: _navigationItems(context).map((item) {
|
destinations: _navigationItems(context).map((item) {
|
||||||
final isDestinationLibrary = item.name == S.of(context).library;
|
final isDestinationLibrary = item.name == S.of(context).library;
|
||||||
var currentLibrary = ref.watch(currentLibraryProvider).valueOrNull;
|
var currentLibrary =
|
||||||
|
ref.watch(currentLibraryProvider).valueOrNull;
|
||||||
final libraryIcon = AbsIcons.getIconByName(
|
final libraryIcon = AbsIcons.getIconByName(
|
||||||
currentLibrary?.icon,
|
currentLibrary?.icon,
|
||||||
);
|
);
|
||||||
|
|
@ -125,9 +126,13 @@ class ScaffoldWithNavBar extends HookConsumerWidget {
|
||||||
isDestinationLibrary ? libraryIcon ?? item.icon : item.icon,
|
isDestinationLibrary ? libraryIcon ?? item.icon : item.icon,
|
||||||
),
|
),
|
||||||
selectedIcon: Icon(
|
selectedIcon: Icon(
|
||||||
isDestinationLibrary ? libraryIcon ?? item.activeIcon : item.activeIcon,
|
isDestinationLibrary
|
||||||
|
? libraryIcon ?? item.activeIcon
|
||||||
|
: item.activeIcon,
|
||||||
),
|
),
|
||||||
label: Text(isDestinationLibrary ? currentLibrary?.name ?? item.name : item.name),
|
label: Text(isDestinationLibrary
|
||||||
|
? currentLibrary?.name ?? item.name
|
||||||
|
: item.name),
|
||||||
// tooltip: item.tooltip,
|
// tooltip: item.tooltip,
|
||||||
);
|
);
|
||||||
// if (isDestinationLibrary) {
|
// if (isDestinationLibrary) {
|
||||||
|
|
@ -166,8 +171,8 @@ class ScaffoldWithNavBar extends HookConsumerWidget {
|
||||||
// useValueListenable(ref.watch(playerExpandProgressNotifierProvider));
|
// useValueListenable(ref.watch(playerExpandProgressNotifierProvider));
|
||||||
final playerProgress = ref.watch(playerHeightProvider);
|
final playerProgress = ref.watch(playerHeightProvider);
|
||||||
final playerMaxHeight = MediaQuery.of(context).size.height;
|
final playerMaxHeight = MediaQuery.of(context).size.height;
|
||||||
var percentExpandedMiniPlayer =
|
var percentExpandedMiniPlayer = (playerProgress - playerMinHeight) /
|
||||||
(playerProgress - playerMinHeight) / (playerMaxHeight - playerMinHeight);
|
(playerMaxHeight - playerMinHeight);
|
||||||
// Clamp the value between 0 and 1
|
// Clamp the value between 0 and 1
|
||||||
percentExpandedMiniPlayer = percentExpandedMiniPlayer.clamp(0.0, 1.0);
|
percentExpandedMiniPlayer = percentExpandedMiniPlayer.clamp(0.0, 1.0);
|
||||||
return Opacity(
|
return Opacity(
|
||||||
|
|
@ -193,9 +198,13 @@ class ScaffoldWithNavBar extends HookConsumerWidget {
|
||||||
isDestinationLibrary ? libraryIcon ?? item.icon : item.icon,
|
isDestinationLibrary ? libraryIcon ?? item.icon : item.icon,
|
||||||
),
|
),
|
||||||
selectedIcon: Icon(
|
selectedIcon: Icon(
|
||||||
isDestinationLibrary ? libraryIcon ?? item.activeIcon : item.activeIcon,
|
isDestinationLibrary
|
||||||
|
? libraryIcon ?? item.activeIcon
|
||||||
|
: item.activeIcon,
|
||||||
),
|
),
|
||||||
label: isDestinationLibrary ? currentLibrary?.name ?? item.name : item.name,
|
label: isDestinationLibrary
|
||||||
|
? currentLibrary?.name ?? item.name
|
||||||
|
: item.name,
|
||||||
tooltip: item.tooltip,
|
tooltip: item.tooltip,
|
||||||
);
|
);
|
||||||
if (isDestinationLibrary) {
|
if (isDestinationLibrary) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue