wip: DropdownButton and TextField on DataTable.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:dde_gesture_manager/constants/constants.dart';
|
||||
import 'package:dde_gesture_manager/extensions.dart';
|
||||
import 'package:dde_gesture_manager/models/settings.provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:glass_kit/glass_kit.dart';
|
||||
|
||||
@@ -8,6 +9,8 @@ class DButton extends StatefulWidget {
|
||||
final double height;
|
||||
final Widget child;
|
||||
final GestureTapCallback? onTap;
|
||||
final EdgeInsets? padding;
|
||||
final Color? activeBorderColor;
|
||||
|
||||
const DButton({
|
||||
Key? key,
|
||||
@@ -15,6 +18,8 @@ class DButton extends StatefulWidget {
|
||||
this.height = defaultButtonHeight,
|
||||
required this.child,
|
||||
this.onTap,
|
||||
this.padding,
|
||||
this.activeBorderColor,
|
||||
}) : super(key: key);
|
||||
|
||||
factory DButton.add({
|
||||
@@ -85,6 +90,22 @@ class DButton extends StatefulWidget {
|
||||
message: LocaleKeys.operation_duplicate.tr(),
|
||||
));
|
||||
|
||||
factory DButton.dropdown({
|
||||
Key? key,
|
||||
width = 60.0,
|
||||
height = kMinInteractiveDimension * .86,
|
||||
padding: const EdgeInsets.only(left: 15),
|
||||
required enabled,
|
||||
required DropdownButton child,
|
||||
}) =>
|
||||
DButton(
|
||||
key: key,
|
||||
width: width,
|
||||
height: height,
|
||||
padding: padding,
|
||||
child: child,
|
||||
);
|
||||
|
||||
@override
|
||||
State<DButton> createState() => _DButtonState();
|
||||
}
|
||||
@@ -95,8 +116,9 @@ class _DButtonState extends State<DButton> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: widget.onTap,
|
||||
onTap: widget.child is DropdownButton ? (widget.child as DropdownButton).onTap : widget.onTap,
|
||||
child: GlassContainer(
|
||||
padding: widget.padding,
|
||||
width: widget.width,
|
||||
height: widget.height,
|
||||
gradient: LinearGradient(
|
||||
@@ -104,8 +126,9 @@ class _DButtonState extends State<DButton> {
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
borderColor: Color(0xff565656),
|
||||
borderWidth: 1,
|
||||
borderColor:
|
||||
_hovering ? widget.activeBorderColor ?? context.watch<SettingsProvider>().activeColor : Color(0xff565656),
|
||||
borderWidth: 2,
|
||||
borderRadius: BorderRadius.circular(defaultBorderRadius),
|
||||
child: MouseRegion(
|
||||
onEnter: (event) => setState(() {
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
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';
|
||||
|
||||
class TableCellTextField extends StatefulWidget {
|
||||
final String? initText;
|
||||
final String? hint;
|
||||
final Function(String value) onComplete;
|
||||
|
||||
const TableCellTextField({
|
||||
Key? key,
|
||||
this.initText,
|
||||
this.hint,
|
||||
required this.onComplete,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_TableCellTextFieldState createState() => _TableCellTextFieldState();
|
||||
}
|
||||
|
||||
class _TableCellTextFieldState extends State<TableCellTextField> {
|
||||
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 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: EdgeInsets.only(left: 15),
|
||||
child: TextField(
|
||||
focusNode: _focusNode,
|
||||
cursorColor: context.watch<SettingsProvider>().activeColor,
|
||||
decoration: InputDecoration.collapsed(hintText: widget.hint),
|
||||
controller: _controller,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user