parent
d24a6ae474
commit
f024c39e1f
@ -0,0 +1,77 @@
|
|||||||
|
import 'package:dde_gesture_manager/constants/constants.dart';
|
||||||
|
import 'package:dde_gesture_manager/models/settings.provider.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:dde_gesture_manager/extensions.dart';
|
||||||
|
|
||||||
|
class DTextField extends StatefulWidget {
|
||||||
|
final String? initText;
|
||||||
|
final String? hint;
|
||||||
|
final Function(String value) onComplete;
|
||||||
|
|
||||||
|
const DTextField({
|
||||||
|
Key? key,
|
||||||
|
this.initText,
|
||||||
|
this.hint,
|
||||||
|
required this.onComplete,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_DTextFieldState createState() => _DTextFieldState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DTextFieldState extends State<DTextField> {
|
||||||
|
final FocusNode _focusNode = FocusNode();
|
||||||
|
final TextEditingController _controller = TextEditingController();
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_focusNode.addListener(_handleFocusChange);
|
||||||
|
_controller.text = widget.initText ?? '';
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_focusNode.removeListener(_handleFocusChange);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleFocusChange() {
|
||||||
|
if (!_focusNode.hasFocus) {
|
||||||
|
widget.onComplete(_controller.text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Focus(
|
||||||
|
child: Builder(builder: (context) {
|
||||||
|
return Container(
|
||||||
|
height: kMinInteractiveDimension * .86,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(defaultBorderRadius),
|
||||||
|
color: Colors.grey.withOpacity(.3),
|
||||||
|
border: Border.all(
|
||||||
|
width: 2,
|
||||||
|
color: Focus.of(context).hasFocus
|
||||||
|
? context.watch<SettingsProvider>().activeColor ?? Color(0xff565656)
|
||||||
|
: Color(0xff565656)),
|
||||||
|
),
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 15),
|
||||||
|
child: TextField(
|
||||||
|
focusNode: _focusNode,
|
||||||
|
cursorColor: context.watch<SettingsProvider>().activeColor,
|
||||||
|
decoration: InputDecoration.collapsed(hintText: widget.hint),
|
||||||
|
controller: _controller,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue