This commit is contained in:
Gaspard Merten 2023-01-25 13:48:51 +01:00
parent 4c4a08a5b3
commit 6e62a13d8f

View file

@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
final DateTime _kDefaultFirstSelectableDate = DateTime(1900); final DateTime _kDefaultFirstSelectableDate = DateTime(1900);
@ -296,7 +297,7 @@ DateFormat getDateFormatFromDateFieldPickerMode(DateTimeFieldPickerMode mode) {
/// Shows a field with a dropdown arrow ! /// Shows a field with a dropdown arrow !
/// It does not show any popup menu, it'll just trigger onPressed whenever the /// It does not show any popup menu, it'll just trigger onPressed whenever the
/// user does click on it ! /// user does click on it !
class _InputDropdown extends StatelessWidget { class _InputDropdown extends StatefulWidget {
const _InputDropdown({ const _InputDropdown({
Key? key, Key? key,
required this.text, required this.text,
@ -326,9 +327,16 @@ class _InputDropdown extends StatelessWidget {
/// Defaults to false. /// Defaults to false.
final bool isEmpty; final bool isEmpty;
@override
State<_InputDropdown> createState() => _InputDropdownState();
}
class _InputDropdownState extends State<_InputDropdown> {
bool focused = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final InputDecoration effectiveDecoration = decoration ?? final InputDecoration effectiveDecoration = widget.decoration ??
const InputDecoration( const InputDecoration(
suffixIcon: Icon(Icons.arrow_drop_down), suffixIcon: Icon(Icons.arrow_drop_down),
); );
@ -336,13 +344,28 @@ class _InputDropdown extends StatelessWidget {
return MouseRegion( return MouseRegion(
cursor: SystemMouseCursors.click, cursor: SystemMouseCursors.click,
child: GestureDetector( child: GestureDetector(
onTap: onPressed, onTap: widget.onPressed,
child: InputDecorator( child: Focus(
decoration: effectiveDecoration.applyDefaults( onFocusChange: (bool newFocus) => setState(() {
Theme.of(context).inputDecorationTheme, focused = newFocus;
}),
onKey: (_, RawKeyEvent key) {
if (key.isKeyPressed(LogicalKeyboardKey.space)) {
widget.onPressed?.call();
return KeyEventResult.handled;
}
return KeyEventResult.ignored;
},
child: InputDecorator(
isHovering: focused,
decoration: effectiveDecoration.applyDefaults(
Theme.of(context).inputDecorationTheme,
),
isEmpty: widget.isEmpty,
child: widget.text == null
? null
: Text(widget.text!, style: widget.textStyle),
), ),
isEmpty: isEmpty,
child: text == null ? null : Text(text!, style: textStyle),
), ),
), ),
); );