Files
SpotiFLAC-Mobile/lib/widgets/app_switch.dart
T
zarzet 63e1a9b9c8 feat(ui): add Mornye glass theme and adaptive music player
Add a selectable Mornye theme with shared glass controls, dialogs, sheets, notifications, and collection headers while retaining Material components.

Update player artwork, lyrics transitions and highlighting, synchronized rolling time labels, volume controls, and compact navigation. Unify metadata, Library, search, and extension surfaces; preserve restored artwork and report extension load failures.

Validation: full Flutter analyzer clean; 713 tests passed and 4 skipped; pinned Dart formatting and diff checks passed; signed ARM64 and ARM32 release APKs built and verified.
2026-09-19 12:10:10 +07:00

159 lines
4.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:liquid_glass_easy/liquid_glass_easy.dart';
import 'package:spotiflac_android/providers/runtime_profile_provider.dart';
import 'package:spotiflac_android/theme/mornye_theme.dart';
/// One switch style for settings, extension controls and editing sheets.
/// Mornye keeps its wide oval thumb even when glass or motion is disabled.
class AppSwitch extends StatelessWidget {
const AppSwitch({
super.key,
required this.value,
required this.onChanged,
this.adaptive = false,
this.semanticLabel,
});
final bool value;
final ValueChanged<bool>? onChanged;
final bool adaptive;
final String? semanticLabel;
@override
Widget build(BuildContext context) {
if (!context.isMornye) {
return adaptive
? Switch.adaptive(value: value, onChanged: onChanged)
: Switch(value: value, onChanged: onChanged);
}
return Consumer(
builder: (context, ref, _) {
final scheme = Theme.of(context).colorScheme;
final enabled = onChanged != null;
final useGlass =
enabled &&
!MediaQuery.disableAnimationsOf(context) &&
!MediaQuery.highContrastOf(context) &&
(!ref.watch(lowEndDeviceProvider) ||
ref.watch(backdropBlurEnabledProvider));
final inactive = scheme.brightness == Brightness.dark
? const Color(0xff39393d)
: const Color(0xff8e8e93);
final Widget control;
if (useGlass) {
control = Transform.flip(
flipX: Directionality.of(context) == TextDirection.rtl,
child: LiquidGlassSwitch(
value: value,
onChanged: onChanged!,
activeColor: scheme.primary,
inactiveColor: inactive,
),
);
} else {
control = Container(
width: 63,
height: 28,
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
color: value ? scheme.primary : inactive,
borderRadius: BorderRadius.circular(14),
),
child: Align(
alignment: value
? AlignmentDirectional.centerEnd
: AlignmentDirectional.centerStart,
child: Container(
width: 37,
height: 24,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
),
),
);
}
return Semantics(
label: semanticLabel,
toggled: value,
enabled: enabled,
child: Opacity(
opacity: enabled ? 1 : 0.5,
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: enabled ? () => onChanged!(!value) : null,
borderRadius: BorderRadius.circular(22),
// InkWell supplies keyboard activation and an accessible tap
// action; the glass control owns the inner drag gesture.
child: ExcludeSemantics(
child: SizedBox(
width: 71,
height: 44,
child: Center(child: control),
),
),
),
),
),
);
},
);
}
}
class AppSwitchListTile extends StatelessWidget {
const AppSwitchListTile({
super.key,
required this.value,
required this.onChanged,
required this.title,
this.subtitle,
this.contentPadding,
this.adaptive = false,
});
final bool value;
final ValueChanged<bool>? onChanged;
final Widget title;
final Widget? subtitle;
final EdgeInsetsGeometry? contentPadding;
final bool adaptive;
@override
Widget build(BuildContext context) {
if (!context.isMornye) {
return adaptive
? SwitchListTile.adaptive(
value: value,
onChanged: onChanged,
title: title,
subtitle: subtitle,
contentPadding: contentPadding,
)
: SwitchListTile(
value: value,
onChanged: onChanged,
title: title,
subtitle: subtitle,
contentPadding: contentPadding,
);
}
return MergeSemantics(
child: ListTile(
title: title,
subtitle: subtitle,
contentPadding: contentPadding,
enabled: onChanged != null,
onTap: onChanged == null ? null : () => onChanged!(!value),
trailing: AppSwitch(value: value, onChanged: onChanged),
),
);
}
}