mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-11-28 23:25:52 +01:00
M3EButtonGroup autofocuses its first segment. On desktop that took focus from the shortcuts' idle node, so Space pressed the segment instead of toggling playback on the Library songs and albums pages, in Settings rows with a segmented choice and in the equalizer. MaterialExpressiveScope can now keep its child from taking focus as it mounts. The group's segments stay unfocusable until the mounting frame's autofocus pass has run, then Tab and clicks reach them as before. Also drops two unneeded imports from the songs table test.
44 lines
1.2 KiB
Dart
44 lines
1.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// Mounts [child] without letting it take keyboard focus.
|
|
///
|
|
/// `M3EButtonGroup` autofocuses its first enabled segment. On desktop that
|
|
/// moves focus off the app's idle node, so Space presses the segment instead
|
|
/// of toggling playback. The descendants stay unfocusable until the
|
|
/// autofocus pass of the mounting frame has run; after that, Tab and
|
|
/// clicks reach them as usual.
|
|
class SkipAutofocus extends StatefulWidget {
|
|
const SkipAutofocus({super.key, required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
State<SkipAutofocus> createState() => _SkipAutofocusState();
|
|
}
|
|
|
|
class _SkipAutofocusState extends State<SkipAutofocus> {
|
|
var _focusable = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// Autofocus applies in a microtask the mounting frame's build queues. A
|
|
// microtask queued after that frame runs after it.
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
scheduleMicrotask(() {
|
|
if (mounted) setState(() => _focusable = true);
|
|
});
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Focus(
|
|
canRequestFocus: false,
|
|
skipTraversal: true,
|
|
descendantsAreFocusable: _focusable,
|
|
child: widget.child,
|
|
);
|
|
}
|