Skip to content

Commit

Permalink
add TextFieldTapRegion
Browse files Browse the repository at this point in the history
  • Loading branch information
toly1994328 committed Dec 18, 2024
1 parent 736385b commit 33e1990
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 4 deletions.
Binary file modified assets/flutter.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class WidgetDao with HasDatabase, DbTable {
String get name => 'widget';

Future<int> insert(WidgetPo widget) async {
//插入方法
String addSql = //插入数据
String addSql =
"INSERT INTO "
"widget(id,name,nameCN,deprecated,family,lever,linkWidget,info) "
"VALUES (?,?,?,?,?,?,?,?);";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"file": "node1.dart",
"name": "监听点击组件内部和外部",
"desc": [
"通过 Localizations.localeOf(context) 可以根据上下文获取最近上层的 Localizations 组件存储的 Locale 数据信息。"
"【enabled】 : 是否可用 【bool】",
"【onTapOutside】 : 点击外界监听 【TapRegionCallback?】",
"【onTapInside】 : 点击内部监听 【TapRegionCallback?】",
"【groupId】 : 点击区域组标识 【Object?】"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": 281,
"name": "TextFieldTapRegion",
"localName": "输入框点击范围",
"info": "groupId 为 EditableText 的 TapRegion,可以让其他组件的点击范围与输入框视为一体。",
"lever": 3,
"family": 2,
"linkIds": [
280,
54,
245
],
"nodes": [
{
"file": "node1.dart",
"name": "监听点击组件内部和外部",
"desc": [
"案例中点击加号和减号,不会取消输入框的焦点,键盘仍然可以输入。",
"【enabled】 : 是否可用 【bool】",
"【onTapOutside】 : 点击外界监听 【TapRegionCallback?】",
"【onTapInside】 : 点击内部监听 【TapRegionCallback?】",
"【groupId】 : 点击区域组标识 【Object?】"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';

class TextFieldTapRegionDemo1 extends StatefulWidget {
const TextFieldTapRegionDemo1({super.key});

@override
State<TextFieldTapRegionDemo1> createState() => _TextFieldTapRegionDemo1State();
}

class _TextFieldTapRegionDemo1State extends State<TextFieldTapRegionDemo1> {
TextEditingController controller = TextEditingController(text: '0');

@override
Widget build(BuildContext context) {
return SizedBox(
width: 160,
child: Row(
children: [
Expanded(child: _buildInput()),
const SizedBox(width: 8),
TextFieldTapRegion(child: buildButtons())
],
),
);
}

Widget _buildInput() {
return TextField(
autofocus: true,
decoration: const InputDecoration(
border: OutlineInputBorder(),
),
onChanged: _onChange,
controller: controller,
textAlign: TextAlign.center,
);
}

void _onChange(String value) {}

Widget buildButtons() {
ButtonStyle style = circleStyle;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
OutlinedButton(
style: style,
onPressed: _increment,
child: const Icon(Icons.add, size: 16),
),
const SizedBox(height: 2),
OutlinedButton(
onPressed: _decrement,
style: style,
child: const Icon(Icons.remove, size: 16),
),
],
);
}

ButtonStyle get circleStyle => OutlinedButton.styleFrom(
shape: const StadiumBorder(),
padding: EdgeInsets.zero,
minimumSize: const Size(32, 32),
maximumSize: const Size(32, 32),
);

void _increment() {
int value = int.tryParse(controller.text) ?? 0;
_updateText('${value + 1}', collapsed: true);
}

void _decrement() {
int value = int.tryParse(controller.text) ?? 0;
_updateText('${value - 1}', collapsed: true);
}

void _updateText(String text, {bool collapsed = true}) {
if (text != controller.text) {
controller.value = TextEditingValue(
text: text,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ export '../SingleChildRenderObjectWidget/PhysicalShape/node1_base.dart';
export '../SingleChildRenderObjectWidget/ImageFiltered/node1_blur.dart';
export '../SingleChildRenderObjectWidget/ImageFiltered/node2_color.dart';
export '../SingleChildRenderObjectWidget/ImageFiltered/node3_matrix.dart';
export '../SingleChildRenderObjectWidget/TapRegion/node1.dart';
export '../SingleChildRenderObjectWidget/TapRegion/node1.dart';
export '../SingleChildRenderObjectWidget/TextFieldTapRegion/node1.dart';
1 change: 1 addition & 0 deletions modules/widget_system/widgets/lib/node_display_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Widget mapNodeDisplay(int widgetId, int nodePriority) {
'76#0' => const CustomSizedBox(),
'84#0' => const CustomSizedOverflowBox(),
'280#0' => const TapRegionDemo1(),
'281#0' => const TextFieldTapRegionDemo1(),
'78#0' => const SkewTransform(),
'78#1' => const TranslationTransform(),
'78#2' => const ScaleTransform(),
Expand Down

0 comments on commit 33e1990

Please sign in to comment.