forked from toly1994328/FlutterUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
736385b
commit 33e1990
Showing
7 changed files
with
119 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...idget_system/widgets/lib/SingleChildRenderObjectWidget/TextFieldTapRegion/desc_zh-CN.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?】" | ||
] | ||
} | ||
] | ||
} |
85 changes: 85 additions & 0 deletions
85
...les/widget_system/widgets/lib/SingleChildRenderObjectWidget/TextFieldTapRegion/node1.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters