2021-06-24 23:10:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cwtch/settings.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
// Provides a styled Text Field for use in Form Widgets.
|
|
|
|
// Callers must provide a text controller, label helper text and a validator.
|
|
|
|
class CwtchButtonTextField extends StatefulWidget {
|
2022-02-05 00:37:25 +00:00
|
|
|
CwtchButtonTextField({
|
|
|
|
required this.controller,
|
|
|
|
required this.onPressed,
|
|
|
|
required this.icon,
|
|
|
|
required this.tooltip,
|
|
|
|
this.readonly = true,
|
|
|
|
this.labelText,
|
|
|
|
this.testKey,
|
|
|
|
this.onChanged,
|
2023-08-02 17:26:09 +00:00
|
|
|
this.textStyle,
|
2022-02-05 00:37:25 +00:00
|
|
|
});
|
2021-06-24 23:10:45 +00:00
|
|
|
final TextEditingController controller;
|
|
|
|
final Function()? onPressed;
|
2022-02-05 00:37:25 +00:00
|
|
|
final Function(String)? onChanged;
|
2021-06-24 23:10:45 +00:00
|
|
|
final Icon icon;
|
|
|
|
final String tooltip;
|
|
|
|
final bool readonly;
|
2022-02-05 00:37:25 +00:00
|
|
|
final Key? testKey;
|
2023-08-02 17:26:09 +00:00
|
|
|
final TextStyle? textStyle;
|
2021-11-19 00:09:55 +00:00
|
|
|
String? labelText;
|
2021-06-24 23:10:45 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
_CwtchButtonTextFieldState createState() => _CwtchButtonTextFieldState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CwtchButtonTextFieldState extends State<CwtchButtonTextField> {
|
|
|
|
late final FocusNode _focusNode;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_focusNode = FocusNode();
|
|
|
|
_focusNode.addListener(() {
|
|
|
|
// Select all...
|
|
|
|
if (_focusNode.hasFocus) widget.controller.selection = TextSelection(baseOffset: 0, extentOffset: widget.controller.text.length);
|
|
|
|
});
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Consumer<Settings>(builder: (context, theme, child) {
|
2023-02-16 21:46:48 +00:00
|
|
|
return Container(
|
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
decoration: BoxDecoration(),
|
2024-02-07 16:16:33 +00:00
|
|
|
// Horrifying Hack: Flutter doesn't give us direct control over system menus but instead picks BG color from TextButtonThemeData ¯\_(ツ)_/¯
|
|
|
|
child: Theme(
|
|
|
|
data: Theme.of(context).copyWith(
|
|
|
|
textButtonTheme: TextButtonThemeData(
|
|
|
|
style: ButtonStyle(backgroundColor: MaterialStateProperty.all(Provider.of<Settings>(context).theme.menuBackgroundColor)),
|
2023-02-16 21:46:48 +00:00
|
|
|
),
|
2024-02-07 16:16:33 +00:00
|
|
|
),
|
|
|
|
child: TextFormField(
|
|
|
|
key: widget.testKey,
|
|
|
|
controller: widget.controller,
|
|
|
|
readOnly: widget.readonly,
|
|
|
|
showCursor: !widget.readonly,
|
|
|
|
focusNode: _focusNode,
|
|
|
|
enableIMEPersonalizedLearning: false,
|
|
|
|
onChanged: widget.onChanged,
|
|
|
|
maxLines: 1,
|
|
|
|
style: widget.textStyle == null ? TextStyle(overflow: TextOverflow.clip) : widget.textStyle,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
labelText: widget.labelText,
|
|
|
|
labelStyle: TextStyle(color: theme.current().mainTextColor, backgroundColor: theme.current().textfieldBackgroundColor),
|
|
|
|
suffixIcon: IconButton(
|
|
|
|
onPressed: widget.onPressed,
|
|
|
|
icon: widget.icon,
|
|
|
|
splashRadius: Material.defaultSplashRadius / 2,
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 4.0, 2.0, 2.0),
|
|
|
|
tooltip: widget.tooltip,
|
|
|
|
enableFeedback: true,
|
|
|
|
color: theme.current().mainTextColor,
|
|
|
|
highlightColor: theme.current().defaultButtonColor,
|
|
|
|
focusColor: theme.current().defaultButtonActiveColor,
|
|
|
|
splashColor: theme.current().defaultButtonActiveColor,
|
|
|
|
),
|
|
|
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
|
|
filled: true,
|
|
|
|
fillColor: theme.current().textfieldBackgroundColor,
|
|
|
|
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(6.0), borderSide: BorderSide(color: theme.current().textfieldBorderColor, width: 1.0)),
|
|
|
|
focusedErrorBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(6.0), borderSide: BorderSide(color: theme.current().textfieldErrorColor, width: 1.0)),
|
|
|
|
errorBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(6.0), borderSide: BorderSide(color: theme.current().textfieldErrorColor, width: 1.0)),
|
|
|
|
errorStyle: TextStyle(
|
|
|
|
color: theme.current().textfieldErrorColor,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
|
|
|
|
enabledBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(6.0), borderSide: BorderSide(color: theme.current().textfieldBorderColor, width: 1.0))),
|
|
|
|
)));
|
2021-06-24 23:10:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|