Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
flutter_clx_base
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
flutter_clx_base
Commits
19fa402c
提交
19fa402c
authored
8月 16, 2022
作者:
shixiaochen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1、增加SearchAppBar
上级
ea42cd1d
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
263 行增加
和
0 行删除
+263
-0
flutter_clx_base.dart
lib/flutter_clx_base.dart
+1
-0
keyboard_utils.dart
lib/utils/keyboard_utils.dart
+35
-0
string_util.dart
lib/utils/string_util.dart
+98
-0
search_app_bar.dart
lib/widget/search_app_bar.dart
+129
-0
没有找到文件。
lib/flutter_clx_base.dart
浏览文件 @
19fa402c
...
...
@@ -6,3 +6,4 @@ export 'utils/image_utils.dart';
export
'widget/my_app_bar.dart'
;
export
'widget/my_scaffold.dart'
;
export
'widget/my_scroll_view.dart'
;
export
'widget/search_app_bar.dart'
;
lib/utils/keyboard_utils.dart
0 → 100644
浏览文件 @
19fa402c
import
'package:flutter/material.dart'
;
import
'package:keyboard_actions/keyboard_actions.dart'
;
class
KeyBoardUtils
{
static
KeyboardActionsConfig
getKeyboardActionsConfig
(
BuildContext
context
,
List
<
FocusNode
>
list
)
{
return
KeyboardActionsConfig
(
keyboardBarColor:
Colors
.
grey
[
200
],
nextFocus:
true
,
actions:
List
.
generate
(
list
.
length
,
(
i
)
=>
KeyboardActionsItem
(
focusNode:
list
[
i
],
toolbarButtons:
[
(
node
)
{
return
GestureDetector
(
onTap:
()
=>
node
.
unfocus
(),
child:
const
Padding
(
padding:
EdgeInsets
.
only
(
right:
16.0
),
child:
Text
(
'关闭'
),
),
);
},
],
)),
);
}
//隐藏键盘
static
void
hideKeyboard
()
{
FocusManager
.
instance
.
primaryFocus
?.
unfocus
();
}
}
lib/utils/string_util.dart
0 → 100644
浏览文件 @
19fa402c
import
'package:flutter/material.dart'
;
bool
isNullOrEmpty
(
String
?
txt
)
{
return
txt
==
null
||
txt
.
isEmpty
;
}
bool
isMobile
(
String
?
mobile
)
{
return
!
isNullOrEmpty
(
mobile
)
&&
mobile
!.
length
==
11
&&
mobile
.
startsWith
(
"1"
);
}
///判断文字是否为空
String
txtIsNull
(
txt
,
{
nullTxt
=
"-"
})
{
if
(
txt
==
null
||
txt
==
""
)
{
return
nullTxt
;
}
else
{
return
txt
;
}
}
String
txtIsNullWithTitle
(
txt
,
title
,
{
nullTxt
=
"-"
})
{
if
(
txt
==
null
||
txt
==
""
)
{
return
nullTxt
;
}
else
{
return
title
+
": "
+
txt
;
}
}
///设置文字长度
String
txtLength
(
String
?
txt
,
{
int
?
length
,
nullTxt
=
""
})
{
if
(
txt
==
null
||
txt
==
""
)
{
return
nullTxt
;
}
else
{
if
(
length
!=
null
&&
txt
.
length
>
length
)
{
return
"
${txt.substring(0, length)}
..."
;
}
return
txt
;
}
}
//时间去除.0
String
?
rightTime
(
String
?
time
)
{
String
?
rightTime
=
time
;
if
(
time
!=
null
&&
time
!=
""
&&
time
.
contains
(
"."
))
{
rightTime
=
time
.
split
(
"."
)[
0
];
}
return
rightTime
;
}
//获取当前时间
String
?
getNowTime
()
{
return
rightTime
(
DateTime
.
now
().
toString
());
}
//获取输入框内的信息
String
getControllerString
(
TextEditingController
controller
)
{
return
controller
.
value
.
text
.
toString
().
trim
();
}
//获取输入框内的文字长度
int
getControllerStringLength
(
TextEditingController
controller
)
{
return
getControllerString
(
controller
).
length
;
}
bool
checkEasyPwd
(
String
input
,
String
phone
)
{
//1:不能出现连续的字母或者数字
var
allMatchLength
=
input
.
length
-
1
;
// 匹配全部
var
preMatchLength
=
input
.
length
-
2
;
// 匹配N-1位
RegExp
allSameChar
=
new
RegExp
(
"([0-9a-zA-Z])
\\
1{
$allMatchLength
}"
);
// 匹配全为连续字符
RegExp
preSameChar
=
new
RegExp
(
"([0-9a-zA-Z])
\\
1{
$preMatchLength
}"
);
// 匹配n-1位位连续字符
//2:不能出现顺子(123456或654321一类) 连续的数字
// allSuccessiveNum 顺子
// startCharSuccessiveNum 第一位字母 后面顺子
// endCharSuccessiveNum 最后一位字母 前面顺子
RegExp
allSuccessiveNum
=
new
RegExp
(
"(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)|9(?=0)){
$allMatchLength
}
\\
d|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){
$allMatchLength
}
\\
d"
);
RegExp
startCharSuccessiveNum
=
new
RegExp
(
"[A-Za-z](?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){
$preMatchLength
}
\\
d|[A-Za-z](?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){
$preMatchLength
}
\\
d"
);
RegExp
endCharSuccessiveNum
=
new
RegExp
(
"((?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){
$preMatchLength
}
\\
d)[A-Za-z]|((?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){
$preMatchLength
}
\\
d)[A-Za-z]"
);
// print('----- allSameChar: $allSameChar');
// print('----- preSameChar: $preSameChar');
// print('----- allSuccessiveNum: $allSuccessiveNum');
// print('----- startCharSuccessiveNum: $startCharSuccessiveNum');
// print('----- endCharSuccessiveNum: $endCharSuccessiveNum');
// print('----- allSameChar: $input ${allSameChar.hasMatch(input)}');
// print('----- preSameChar: $input ${preSameChar.hasMatch(input)}');
// print('----- allSuccessiveNum: $input ${allSuccessiveNum.hasMatch(input)}');
// print('----- startCharSuccessiveNum: $input ${startCharSuccessiveNum.hasMatch(input)}');
// print('----- endCharSuccessiveNum: $input ${endCharSuccessiveNum.hasMatch(input)}');
return
allSameChar
.
hasMatch
(
input
)
||
preSameChar
.
hasMatch
(
input
)
||
allSuccessiveNum
.
hasMatch
(
input
)
||
startCharSuccessiveNum
.
hasMatch
(
input
)
||
endCharSuccessiveNum
.
hasMatch
(
input
)
||
phone
.
contains
(
input
);
}
lib/widget/search_app_bar.dart
0 → 100644
浏览文件 @
19fa402c
import
'package:flutter/material.dart'
;
import
'package:flutter_clx_base/common/gaps.dart'
;
import
'package:flutter_clx_base/utils/keyboard_utils.dart'
;
import
'package:flutter_clx_base/utils/string_util.dart'
;
import
'package:flutter_clx_base/utils/toast_util.dart'
;
import
'package:get/get.dart'
;
import
'package:keyboard_actions/keyboard_actions.dart'
;
class
SearchAppBar
extends
StatefulWidget
implements
PreferredSizeWidget
{
final
Function
?
onCallback
;
final
String
?
hintText
;
final
bool
showLeading
;
final
Color
backgroundColor
;
final
bool
primary
;
const
SearchAppBar
({
Key
?
key
,
this
.
onCallback
,
this
.
hintText
=
"请输入搜索内容"
,
this
.
showLeading
=
true
,
this
.
backgroundColor
=
Colors
.
blue
,
this
.
primary
=
true
,
})
:
super
(
key:
key
);
@override
State
<
SearchAppBar
>
createState
()
=>
_SearchAppBarState
();
@override
Size
get
preferredSize
=>
const
Size
(
double
.
infinity
,
55.0
);
}
class
_SearchAppBarState
extends
State
<
SearchAppBar
>
{
final
searchInfoController
=
TextEditingController
();
final
searchFocusNode
=
FocusNode
();
@override
Widget
build
(
BuildContext
context
)
{
return
KeyboardActions
(
config:
KeyBoardUtils
.
getKeyboardActionsConfig
(
context
,
[
searchFocusNode
]),
tapOutsideBehavior:
TapOutsideBehavior
.
opaqueDismiss
,
child:
AppBar
(
backgroundColor:
widget
.
backgroundColor
,
titleSpacing:
0.0
,
primary:
widget
.
primary
,
leading:
widget
.
showLeading
?
InkWell
(
onTap:
()
=>
Get
.
back
(),
child:
const
Icon
(
Icons
.
arrow_back_ios
,
color:
Colors
.
white
),
)
:
Container
(),
leadingWidth:
widget
.
showLeading
?
null
:
0.0
,
title:
Container
(
color:
Colors
.
blue
,
child:
Row
(
children:
<
Widget
>[
Expanded
(
child:
Container
(
decoration:
const
BoxDecoration
(
borderRadius:
BorderRadius
.
all
(
Radius
.
circular
(
20.0
)),
color:
Color
(
0xFFEEEEEE
),
),
child:
Row
(
children:
<
Widget
>[
hGap10
,
Icon
(
Icons
.
search
,
color:
Colors
.
grey
.
shade300
),
hGap5
,
Expanded
(
child:
TextField
(
maxLines:
1
,
focusNode:
searchFocusNode
,
style:
const
TextStyle
(
fontSize:
14
),
textInputAction:
TextInputAction
.
search
,
controller:
searchInfoController
,
onSubmitted:
(
value
)
=>
_search
(),
decoration:
InputDecoration
(
contentPadding:
const
EdgeInsets
.
symmetric
(
horizontal:
0.0
,
vertical:
8.0
),
isDense:
true
,
counterText:
""
,
hintText:
widget
.
hintText
,
hintStyle:
const
TextStyle
(
fontSize:
14.0
,
color:
Color
(
0xFF999999
)),
border:
InputBorder
.
none
,
//去掉下划线
//hintStyle: TextStyles.textGrayC14
),
),
),
],
),
),
),
InkWell
(
onTap:
()
=>
_search
(),
child:
Container
(
width:
60.0
,
alignment:
Alignment
.
center
,
child:
const
Text
(
"搜索"
,
style:
TextStyle
(
color:
Color
(
0xFFFFFFFF
),
fontSize:
14.0
),
),
),
)
],
),
),
),
);
}
/// 校验
bool
_checkInfo
()
{
if
(
isNullOrEmpty
(
getControllerString
(
searchInfoController
)))
{
ToastUtil
.
showToast
(
"请输入搜索内容"
);
return
false
;
}
return
true
;
}
/// 搜索
void
_search
()
{
if
(
_checkInfo
())
{
KeyBoardUtils
.
hideKeyboard
();
if
(
widget
.
onCallback
!=
null
)
{
widget
.
onCallback
!(
getControllerString
(
searchInfoController
));
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论