Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated package [navbar][input] to null-safety #75

Merged
merged 16 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions lib/src/components/input/brn_input_text.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

import 'package:bruno/src/theme/brn_theme_configurator.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -21,10 +19,10 @@ typedef BrnInputTextEditingCompleteCallback = Function(String input);

class BrnInputText extends StatelessWidget {
/// 搜索框输入内容改变时候的回调函数
final BrnInputTextChangeCallback onTextChange;
final BrnInputTextChangeCallback? onTextChange;

/// 点击确定后的回调
final BrnInputTextSubmitCallback onSubmit;
final BrnInputTextSubmitCallback? onSubmit;

/// 容器的最大高度,默认 200
final double maxHeight;
Expand All @@ -39,10 +37,11 @@ class BrnInputText extends StatelessWidget {
final String hint;

/// 输入框的初始值,默认为""
/// 不能定义为String,兼容example调用的传值
final String textString;

/// 用于对 TextField 更精细的控制,若传入该字段,[textString] 参数将失效,可使用 TextEditingController.text 进行赋值。
final TextEditingController textEditingController;
final TextEditingController? textEditingController;

/// 最大字数,默认200
final int maxLength;
Expand All @@ -54,22 +53,22 @@ class BrnInputText extends StatelessWidget {
final EdgeInsetsGeometry padding;

/// 最大hint行数
final int maxHintLines;
final int? maxHintLines;

/// 搜索框的焦点控制器
final FocusNode focusNode;
final FocusNode? focusNode;

/// 键盘输入行为, 默认为 TextInputAction.done
final TextInputAction textInputAction;

/// 光标展示
final bool autoFocus;
final bool? autoFocus;

/// 背景圆角
final double borderRadius;
final double? borderRadius;

/// 边框颜色
final Color borderColor;
final Color? borderColor;

BrnInputText({
this.onTextChange,
Expand Down Expand Up @@ -98,13 +97,13 @@ class BrnInputText extends StatelessWidget {

Widget _inputText(BuildContext context) {
String textData = textString;
if (textData != null && textString.runes.length > maxLength) {
if (textString.runes.length > maxLength) {
var sRunes = textData.runes;
textData = String.fromCharCodes(sRunes, 0, maxLength);
}
var _controller = textEditingController;
if (_controller == null) {
if (textData != null && textData.length > 0) {
if (textData.isNotEmpty) {
_controller = TextEditingController.fromValue(TextEditingValue(
text: textData,
selection: TextSelection.fromPosition(TextPosition(
Expand All @@ -130,7 +129,7 @@ class BrnInputText extends StatelessWidget {
controller: _controller,
keyboardType: TextInputType.multiline,
maxLength: maxLength,
maxLengthEnforced: true,
maxLengthEnforcement: MaxLengthEnforcement.enforced,
maxLines: null,
autofocus: autoFocus ?? true,
focusNode: focusNode,
Expand All @@ -143,8 +142,12 @@ class BrnInputText extends StatelessWidget {
.getConfig()
.commonConfig
.colorTextBase),
buildCounter: (BuildContext context,
{int currentLength, int maxLength, bool isFocused}) {
buildCounter: (
BuildContext context, {
required int currentLength,
required int? maxLength,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 164 会不会有问题,因为 maxLength可空

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不会。因为BrnInputText的maxLength是非空类型,【148行的maxLength】的值是由【BrnInputText的maxLength】传递过去的。

required bool isFocused,
}) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Expand Down Expand Up @@ -184,12 +187,13 @@ class BrnInputText extends StatelessWidget {
),
onSubmitted: (text) {
if (onSubmit != null) {
onSubmit(text);
onSubmit!(text);
}
},

onChanged: (text) {
if (onTextChange != null) {
onTextChange(text);
onTextChange!(text);
}
},
),
Expand Down
Loading