mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: deprecate InputTextField (#1566)
This commit is contained in:
parent
873a46e443
commit
f9cc05319b
@ -56,6 +56,7 @@ class _SliverChecklistPrograssBarDelegate
|
|||||||
children: [
|
children: [
|
||||||
FlowyTextField(
|
FlowyTextField(
|
||||||
autoClearWhenDone: true,
|
autoClearWhenDone: true,
|
||||||
|
submitOnLeave: true,
|
||||||
hintText: LocaleKeys.grid_checklist_panelTitle.tr(),
|
hintText: LocaleKeys.grid_checklist_panelTitle.tr(),
|
||||||
onChanged: (text) {
|
onChanged: (text) {
|
||||||
context
|
context
|
||||||
|
@ -17,7 +17,7 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
|
|||||||
import 'package:textfield_tags/textfield_tags.dart';
|
import 'package:textfield_tags/textfield_tags.dart';
|
||||||
|
|
||||||
import '../../../layout/sizes.dart';
|
import '../../../layout/sizes.dart';
|
||||||
import '../../common/text_field.dart';
|
import '../../common/type_option_separator.dart';
|
||||||
import '../../header/type_option/select_option_editor.dart';
|
import '../../header/type_option/select_option_editor.dart';
|
||||||
import 'extension.dart';
|
import 'extension.dart';
|
||||||
import 'text_field.dart';
|
import 'text_field.dart';
|
||||||
|
@ -1,108 +0,0 @@
|
|||||||
import 'package:flowy_infra_ui/widget/rounded_input_field.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/scheduler.dart';
|
|
||||||
|
|
||||||
class InputTextField extends StatefulWidget {
|
|
||||||
final void Function(String)? onDone;
|
|
||||||
final void Function(String)? onChanged;
|
|
||||||
final void Function() onCanceled;
|
|
||||||
final bool autoClearWhenDone;
|
|
||||||
final String text;
|
|
||||||
final int? maxLength;
|
|
||||||
final FocusNode? focusNode;
|
|
||||||
|
|
||||||
const InputTextField({
|
|
||||||
required this.text,
|
|
||||||
this.onDone,
|
|
||||||
required this.onCanceled,
|
|
||||||
this.onChanged,
|
|
||||||
this.autoClearWhenDone = false,
|
|
||||||
this.maxLength,
|
|
||||||
this.focusNode,
|
|
||||||
Key? key,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<InputTextField> createState() => _InputTextFieldState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _InputTextFieldState extends State<InputTextField> {
|
|
||||||
late FocusNode _focusNode;
|
|
||||||
var isEdited = false;
|
|
||||||
late TextEditingController _controller;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
_focusNode = widget.focusNode ?? FocusNode();
|
|
||||||
_controller = TextEditingController(text: widget.text);
|
|
||||||
SchedulerBinding.instance.addPostFrameCallback((Duration _) {
|
|
||||||
_focusNode.requestFocus();
|
|
||||||
});
|
|
||||||
|
|
||||||
_focusNode.addListener(notifyDidEndEditing);
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return RoundedInputField(
|
|
||||||
controller: _controller,
|
|
||||||
focusNode: _focusNode,
|
|
||||||
autoFocus: true,
|
|
||||||
height: 36.0,
|
|
||||||
maxLength: widget.maxLength,
|
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
|
||||||
onChanged: (text) {
|
|
||||||
if (widget.onChanged != null) {
|
|
||||||
widget.onChanged!(text);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onEditingComplete: (_) {
|
|
||||||
if (widget.onDone != null) {
|
|
||||||
widget.onDone!(_controller.text);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (widget.autoClearWhenDone) {
|
|
||||||
_controller.text = "";
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void dispose() {
|
|
||||||
_focusNode.removeListener(notifyDidEndEditing);
|
|
||||||
// only dispose the focusNode if it was created in this widget's initState
|
|
||||||
if (widget.focusNode == null) {
|
|
||||||
_focusNode.dispose();
|
|
||||||
}
|
|
||||||
super.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
void notifyDidEndEditing() {
|
|
||||||
if (!_focusNode.hasFocus) {
|
|
||||||
if (_controller.text.isEmpty) {
|
|
||||||
widget.onCanceled();
|
|
||||||
} else {
|
|
||||||
if (widget.onDone != null) {
|
|
||||||
widget.onDone!(_controller.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class TypeOptionSeparator extends StatelessWidget {
|
|
||||||
const TypeOptionSeparator({Key? key}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
|
||||||
child: Container(
|
|
||||||
color: Theme.of(context).dividerColor,
|
|
||||||
height: 1.0,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,16 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
class TypeOptionSeparator extends StatelessWidget {
|
||||||
|
const TypeOptionSeparator({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||||
|
child: Container(
|
||||||
|
color: Theme.of(context).dividerColor,
|
||||||
|
height: 1.0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:appflowy_popover/appflowy_popover.dart';
|
import 'package:appflowy_popover/appflowy_popover.dart';
|
||||||
import '../../../layout/sizes.dart';
|
import '../../../layout/sizes.dart';
|
||||||
import '../../common/text_field.dart';
|
import '../../common/type_option_separator.dart';
|
||||||
import '../field_type_option_editor.dart';
|
import '../field_type_option_editor.dart';
|
||||||
import 'builder.dart';
|
import 'builder.dart';
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ import 'package:easy_localization/easy_localization.dart' hide NumberFormat;
|
|||||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||||
|
|
||||||
import '../../../layout/sizes.dart';
|
import '../../../layout/sizes.dart';
|
||||||
import '../../common/text_field.dart';
|
import '../../common/type_option_separator.dart';
|
||||||
import '../field_type_option_editor.dart';
|
import '../field_type_option_editor.dart';
|
||||||
import 'builder.dart';
|
import 'builder.dart';
|
||||||
|
|
||||||
@ -182,12 +182,10 @@ class _FilterTextField extends StatelessWidget {
|
|||||||
const _FilterTextField({Key? key}) : super(key: key);
|
const _FilterTextField({Key? key}) : super(key: key);
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return InputTextField(
|
return FlowyTextField(
|
||||||
text: "",
|
onChanged: (text) => context
|
||||||
onCanceled: () {},
|
.read<NumberFormatBloc>()
|
||||||
onChanged: (text) {
|
.add(NumberFormatEvent.setFilter(text)),
|
||||||
context.read<NumberFormatBloc>().add(NumberFormatEvent.setFilter(text));
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
|
|||||||
|
|
||||||
import '../../../layout/sizes.dart';
|
import '../../../layout/sizes.dart';
|
||||||
import '../../cell/select_option_cell/extension.dart';
|
import '../../cell/select_option_cell/extension.dart';
|
||||||
import '../../common/text_field.dart';
|
import '../../common/type_option_separator.dart';
|
||||||
import 'select_option_editor.dart';
|
import 'select_option_editor.dart';
|
||||||
|
|
||||||
class SelectOptionTypeOptionWidget extends StatelessWidget {
|
class SelectOptionTypeOptionWidget extends StatelessWidget {
|
||||||
@ -282,7 +282,7 @@ class _CreateOptionTextFieldState extends State<_CreateOptionTextField> {
|
|||||||
return BlocBuilder<SelectOptionTypeOptionBloc, SelectOptionTypeOptionState>(
|
return BlocBuilder<SelectOptionTypeOptionBloc, SelectOptionTypeOptionState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final text = state.newOptionName.foldRight("", (a, previous) => a);
|
final text = state.newOptionName.foldRight("", (a, previous) => a);
|
||||||
return InputTextField(
|
return FlowyTextField(
|
||||||
autoClearWhenDone: true,
|
autoClearWhenDone: true,
|
||||||
maxLength: 30,
|
maxLength: 30,
|
||||||
text: text,
|
text: text,
|
||||||
@ -292,7 +292,8 @@ class _CreateOptionTextFieldState extends State<_CreateOptionTextField> {
|
|||||||
.read<SelectOptionTypeOptionBloc>()
|
.read<SelectOptionTypeOptionBloc>()
|
||||||
.add(const SelectOptionTypeOptionEvent.endAddingOption());
|
.add(const SelectOptionTypeOptionEvent.endAddingOption());
|
||||||
},
|
},
|
||||||
onDone: (optionName) {
|
onEditingComplete: () {},
|
||||||
|
onSubmitted: (optionName) {
|
||||||
context
|
context
|
||||||
.read<SelectOptionTypeOptionBloc>()
|
.read<SelectOptionTypeOptionBloc>()
|
||||||
.add(SelectOptionTypeOptionEvent.createOption(optionName));
|
.add(SelectOptionTypeOptionEvent.createOption(optionName));
|
||||||
|
@ -13,7 +13,7 @@ import 'package:easy_localization/easy_localization.dart';
|
|||||||
import 'package:app_flowy/generated/locale_keys.g.dart';
|
import 'package:app_flowy/generated/locale_keys.g.dart';
|
||||||
|
|
||||||
import '../../../layout/sizes.dart';
|
import '../../../layout/sizes.dart';
|
||||||
import '../../common/text_field.dart';
|
import '../../common/type_option_separator.dart';
|
||||||
|
|
||||||
class SelectOptionTypeOptionEditor extends StatelessWidget {
|
class SelectOptionTypeOptionEditor extends StatelessWidget {
|
||||||
final SelectOptionPB option;
|
final SelectOptionPB option;
|
||||||
@ -126,6 +126,7 @@ class _OptionNameTextField extends StatelessWidget {
|
|||||||
autoFocus: autoFocus,
|
autoFocus: autoFocus,
|
||||||
text: name,
|
text: name,
|
||||||
maxLength: 30,
|
maxLength: 30,
|
||||||
|
submitOnLeave: true,
|
||||||
onSubmitted: (newName) {
|
onSubmitted: (newName) {
|
||||||
if (name != newName) {
|
if (name != newName) {
|
||||||
context
|
context
|
||||||
|
@ -9,24 +9,30 @@ class FlowyTextField extends StatefulWidget {
|
|||||||
final String hintText;
|
final String hintText;
|
||||||
final String text;
|
final String text;
|
||||||
final void Function(String)? onChanged;
|
final void Function(String)? onChanged;
|
||||||
|
final void Function()? onEditingComplete;
|
||||||
final void Function(String)? onSubmitted;
|
final void Function(String)? onSubmitted;
|
||||||
final void Function()? onCanceled;
|
final void Function()? onCanceled;
|
||||||
|
final FocusNode? focusNode;
|
||||||
final bool autoFocus;
|
final bool autoFocus;
|
||||||
final int? maxLength;
|
final int? maxLength;
|
||||||
final TextEditingController? controller;
|
final TextEditingController? controller;
|
||||||
final bool autoClearWhenDone;
|
final bool autoClearWhenDone;
|
||||||
|
final bool submitOnLeave;
|
||||||
final Duration? debounceDuration;
|
final Duration? debounceDuration;
|
||||||
|
|
||||||
const FlowyTextField({
|
const FlowyTextField({
|
||||||
this.hintText = "",
|
this.hintText = "",
|
||||||
this.text = "",
|
this.text = "",
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
|
this.onEditingComplete,
|
||||||
this.onSubmitted,
|
this.onSubmitted,
|
||||||
this.onCanceled,
|
this.onCanceled,
|
||||||
|
this.focusNode,
|
||||||
this.autoFocus = true,
|
this.autoFocus = true,
|
||||||
this.maxLength,
|
this.maxLength,
|
||||||
this.controller,
|
this.controller,
|
||||||
this.autoClearWhenDone = false,
|
this.autoClearWhenDone = false,
|
||||||
|
this.submitOnLeave = false,
|
||||||
this.debounceDuration,
|
this.debounceDuration,
|
||||||
Key? key,
|
Key? key,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
@ -42,7 +48,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
focusNode = FocusNode();
|
focusNode = widget.focusNode ?? FocusNode();
|
||||||
focusNode.addListener(notifyDidEndEditing);
|
focusNode.addListener(notifyDidEndEditing);
|
||||||
|
|
||||||
if (widget.controller != null) {
|
if (widget.controller != null) {
|
||||||
@ -77,6 +83,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
|
|||||||
widget.onSubmitted?.call(text);
|
widget.onSubmitted?.call(text);
|
||||||
if (widget.autoClearWhenDone) {
|
if (widget.autoClearWhenDone) {
|
||||||
controller.text = "";
|
controller.text = "";
|
||||||
|
setState(() {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,6 +100,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSubmitted: (text) => _onSubmitted(text),
|
onSubmitted: (text) => _onSubmitted(text),
|
||||||
|
onEditingComplete: widget.onEditingComplete,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
maxLength: widget.maxLength,
|
maxLength: widget.maxLength,
|
||||||
maxLengthEnforcement: MaxLengthEnforcement.truncateAfterCompositionEnds,
|
maxLengthEnforcement: MaxLengthEnforcement.truncateAfterCompositionEnds,
|
||||||
@ -102,7 +110,7 @@ class FlowyTextFieldState extends State<FlowyTextField> {
|
|||||||
const EdgeInsets.symmetric(horizontal: 10, vertical: 13),
|
const EdgeInsets.symmetric(horizontal: 10, vertical: 13),
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: Theme.of(context).colorScheme.primary,
|
color: Theme.of(context).colorScheme.outline,
|
||||||
width: 1.0,
|
width: 1.0,
|
||||||
),
|
),
|
||||||
borderRadius: Corners.s10Border,
|
borderRadius: Corners.s10Border,
|
||||||
@ -135,10 +143,10 @@ class FlowyTextFieldState extends State<FlowyTextField> {
|
|||||||
|
|
||||||
void notifyDidEndEditing() {
|
void notifyDidEndEditing() {
|
||||||
if (!focusNode.hasFocus) {
|
if (!focusNode.hasFocus) {
|
||||||
if (controller.text.isEmpty) {
|
if (controller.text.isNotEmpty && widget.submitOnLeave) {
|
||||||
widget.onCanceled?.call();
|
|
||||||
} else {
|
|
||||||
widget.onSubmitted?.call(controller.text);
|
widget.onSubmitted?.call(controller.text);
|
||||||
|
} else {
|
||||||
|
widget.onCanceled?.call();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user