Files
zarzet 962e582acc chore(flutter): move to Flutter 3.50.0 and the material_ui packages
Flutter 3.50 deprecates its built-in Material and Cupertino libraries in
favour of the material_ui and cupertino_ui packages. The imports move
with the official fix (dart fix, migrate_design_widgets); the app's old
two-library theme bridge collapses into one Theme type.

- MaterialExpressiveScope keeps the complete host theme nearest its
  child. The reduced copy made for the expressive widgets now shares the
  app's Theme type and would hide component themes and extensions.
- LegacyThemeBrightness hands the brightness to the glass package, which
  still reads Flutter's built-in theme.
- appLocalizationsDelegates lists the material_ui localization delegates;
  the generated list still names the built-in ones.
- Tests: findByTooltip and pageBack replace the flutter_test helpers that
  only know the built-in widgets, and several tests that had gone stale
  against earlier app changes are repaired.
2026-11-15 23:33:29 +07:00

151 lines
4.2 KiB
Dart

import 'dart:async';
import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoButton;
import 'package:material_ui/material_ui.dart';
import 'package:mornye/theme/mornye_theme.dart';
import 'package:mornye/widgets/mini_player.dart';
/// Remote destinations stay visible while the content and player own focus.
class TvShell extends StatefulWidget {
const TvShell({
super.key,
required this.destinations,
required this.selectedIndex,
required this.onSelected,
required this.child,
});
final List<NavigationDestination> destinations;
final int selectedIndex;
final ValueChanged<int> onSelected;
final Widget child;
@override
State<TvShell> createState() => _TvShellState();
}
class _TvShellState extends State<TvShell> {
final _destinations = <int, FocusNode>{};
FocusNode _node(int index) => _destinations.putIfAbsent(
index,
() => FocusNode(debugLabel: 'TV destination $index'),
);
@override
void initState() {
super.initState();
_focusDestination(widget.selectedIndex);
}
void _focusDestination(int index) {
// The nested tab Navigator mounts after the sidebar. Wait for its initial
// focus pass before restoring the remote's destination.
WidgetsBinding.instance.addPostFrameCallback((_) {
scheduleMicrotask(() {
if (mounted) _node(index).requestFocus();
});
});
}
void _select(int index) {
widget.onSelected(index);
_focusDestination(index);
}
@override
void dispose() {
for (final node in _destinations.values) {
node.dispose();
}
super.dispose();
}
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return Row(
children: [
SizedBox(
width: 112,
child: ColoredBox(
color: context.isMornye
? MornyeTheme.controlFill(context)
: scheme.surfaceContainer,
child: ListView(
padding: const EdgeInsets.all(8),
children: [
for (var index = 0; index < widget.destinations.length; index++)
Padding(
padding: const EdgeInsets.symmetric(vertical: 4),
child: _destination(context, index),
),
],
),
),
),
Expanded(
child: Column(
children: [
Expanded(child: widget.child),
const MiniPlayer(),
],
),
),
],
);
}
Widget _destination(BuildContext context, int index) {
final destination = widget.destinations[index];
final selected = index == widget.selectedIndex;
final scheme = Theme.of(context).colorScheme;
final content = Semantics(
selected: selected,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
selected
? destination.selectedIcon ?? destination.icon
: destination.icon,
const SizedBox(height: 4),
Text(destination.label, textAlign: TextAlign.center),
],
),
);
if (context.isMornye) {
return CupertinoButton(
focusNode: _node(index),
autofocus: selected,
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 12),
color: selected ? scheme.primary.withValues(alpha: 0.16) : null,
onPressed: () => _select(index),
child: DefaultTextStyle.merge(
style: Theme.of(context).textTheme.labelLarge!.copyWith(
color: selected ? scheme.primary : scheme.onSurface,
),
child: IconTheme.merge(
data: IconThemeData(
color: selected ? scheme.primary : scheme.onSurface,
),
child: content,
),
),
);
}
return TextButton(
focusNode: _node(index),
autofocus: selected,
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 12),
backgroundColor: selected ? scheme.primaryContainer : null,
foregroundColor: selected
? scheme.onPrimaryContainer
: scheme.onSurface,
),
onPressed: () => _select(index),
child: content,
);
}
}