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

migrate picker to null safety #91

Merged
merged 39 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d2a37e0
Theme: 优化单例实现,初步优化 BrnAllThemeConfig 属性获取不为 null
zhoujuanjuan Dec 27, 2021
75a2be3
refactor:优化theme,暴露非null引用
zhoujuanjuan Dec 27, 2021
f97bf07
theme:去除无用信息及优化部分代码
zhoujuanjuan Dec 28, 2021
44ba17a
theme:增加属性类型
zhoujuanjuan Dec 28, 2021
cad7451
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Dec 31, 2021
c19203f
优化修复 EventBus
zhoujuanjuan Dec 31, 2021
c96cdd3
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 4, 2022
2c99d35
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 4, 2022
c7ae392
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 5, 2022
6e0834b
迁移example ,优化常量命名,增加export
zhoujuanjuan Jan 4, 2022
5db665d
migrate brn_empty_status.dart
zhoujuanjuan Jan 5, 2022
7c12fc8
删除 BrnThemeImg
zhoujuanjuan Jan 6, 2022
0b75394
Merge remote-tracking branch 'upstream/null-safe' into null-safe
zhoujuanjuan Jan 6, 2022
c00cfd5
fix:tagConfig merge方法增加判空处理
zhoujuanjuan Jan 6, 2022
ada5216
fix:revert tagConfig
zhoujuanjuan Jan 7, 2022
beec378
fix:BrnAbnormalStateWidget空处理
zhoujuanjuan Jan 7, 2022
b852eb6
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 7, 2022
e69a944
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 10, 2022
e31532f
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 11, 2022
162fcfe
Migrated tabbar to null-safety
zhoujuanjuan Jan 11, 2022
2bd473f
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 12, 2022
103ab13
Migrated scroll_anchor to null-safety
zhoujuanjuan Jan 11, 2022
2b141fd
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 13, 2022
04b7a3e
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 17, 2022
5748da7
fix:修复迁移tabar问题
zhoujuanjuan Jan 17, 2022
8c25d72
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 18, 2022
1c33fd9
migrate form to null safety
zhoujuanjuan Jan 18, 2022
07c308a
fix:修复tabbar报错及selection警告信息
zhoujuanjuan Jan 18, 2022
fdf45af
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 19, 2022
e1749fe
Merge remote-tracking branch 'upstream/null-safe' into null-safe
zhoujuanjuan Jan 24, 2022
0b4c168
fix:修复迁移问题
zhoujuanjuan Jan 24, 2022
3f3b4d3
fix:优化迁移部分问题key和style非空问题
zhoujuanjuan Jan 24, 2022
1b89f72
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 24, 2022
8b9e3ab
migrate picker to null safety
zhoujuanjuan Jan 24, 2022
fbe085a
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 25, 2022
2d7fcc1
fix:修复picker空安全迁移问题
zhoujuanjuan Jan 25, 2022
a23e201
fix:修复list没指定泛型及if判断错误问题
zhoujuanjuan Jan 26, 2022
4fa42f7
Merge branch 'LianjiaTech:null-safe' into null-safe
zhoujuanjuan Jan 26, 2022
33ed04a
fix:migrate dashed line to null safty
zhoujuanjuan Jan 26, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class DatePickerExamplePage extends StatelessWidget {
format = 'HH时:mm分';
BrnPickerTitleConfig timePickerTheme = BrnPickerTitleConfig(
title: BrnPickerTitleConfig.Default.title,
showTitle: PICKER_SHOW_TITLE_DEFAULT,
showTitle: pickerShowTitleDefault,
titleContent: "选择时间范围");
BrnDateRangePicker.showDatePicker(context,
minDateTime: DateTime.parse(MIN_DATETIME),
Expand Down
12 changes: 6 additions & 6 deletions example/lib/sample/components/picker/picker_entry_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PickerEntryPage extends StatelessWidget {
describe: "底部级联选择框",
onPressed: () {
rootBundle.loadString('assets/list_picker.json').then((data) {
List<BrnPickerEntity> _selectionData = List()
List<BrnPickerEntity> _selectionData = []
..addAll((JsonDecoder().convert(data)["data"]['list'] as List ?? [])
.map((o) => BrnPickerEntity.fromMap(o)));
if (_selectionData != null && _selectionData.length > 0) {
Expand All @@ -100,7 +100,7 @@ class PickerEntryPage extends StatelessWidget {
describe: "底部级联选择框(Title 动态改变)",
onPressed: () {
rootBundle.loadString('assets/list_picker.json').then((data) {
List<BrnPickerEntity> _selectionData = List()
List<BrnPickerEntity> _selectionData = []
..addAll((JsonDecoder().convert(data)["data"]['list'] as List ?? [])
.map((o) => BrnPickerEntity.fromMap(o)));
if (_selectionData != null && _selectionData.length > 0) {
Expand Down Expand Up @@ -131,7 +131,7 @@ class PickerEntryPage extends StatelessWidget {

///多选弹框
void _showBottomMultiSelectPicker(BuildContext context) {
List<BrnMultiSelectBottomPickerItem> items = new List();
List<BrnMultiSelectBottomPickerItem> items = [];
items.add(new BrnMultiSelectBottomPickerItem("100", "这里是标题1"));
items.add(new BrnMultiSelectBottomPickerItem("101", "这里是标题2"));
items.add(new BrnMultiSelectBottomPickerItem("102", "这里是标题3", isChecked: true));
Expand Down Expand Up @@ -353,7 +353,7 @@ class PickerEntryPage extends StatelessWidget {
List<BrnTagInputItemBean> items = List();
for (int i = 0; i < tags.length; i++) {
String it = tags[i];
BrnTagInputItemBean item = BrnTagInputItemBean(name: it, index: i, needExplane: (i % 2 == 0));
BrnTagInputItemBean item = BrnTagInputItemBean(name: it, index: i, needExpend: (i % 2 == 0));
items.add(item);
}

Expand All @@ -371,8 +371,8 @@ class PickerEntryPage extends StatelessWidget {
tagItemSource: items,
tagTitleFontSize: 12,
tagTitleColor: Color(0xff222222),
tagBackgroudColor: Color(0xffF8F8F8),
selectedTagBackgroudColor: Color(0x140984F9),
tagBackgroundColor: Color(0xffF8F8F8),
selectedTagBackgroundColor: Color(0x140984F9),
selectedTagTitleColor: Color(0xFF0984F9),
),
onTagValueGetter: (choice) {
Expand Down
73 changes: 36 additions & 37 deletions lib/src/components/picker/base/brn_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9


import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -12,7 +12,7 @@ import 'package:flutter/widgets.dart';

/// Color of the 'magnifier' lens border.
const Color _kHighlighterBorder = Color(0xFFF0F0F0);
const Color _kDefaultBackground = Color(0xFFD2D4DB);
const Color _kDefaultBackground = Color(0xFFFFFFFF);
// Eyeballed values comparing with a native picker to produce the right
// curvatures and densities.
const double _kDefaultDiameterRatio = 3;
Expand Down Expand Up @@ -61,7 +61,7 @@ class BrnPicker extends StatefulWidget {
/// will loop the list back to the beginning. If set to false, the list will
/// stop scrolling when you reach the end or the beginning.
BrnPicker({
Key key,
Key? key,
this.diameterRatio = _kDefaultDiameterRatio,
this.backgroundColor = _kDefaultBackground,
this.lineColor = _kHighlighterBorder,
Expand All @@ -70,9 +70,9 @@ class BrnPicker extends StatefulWidget {
this.magnification = 1.0,
this.scrollController,
this.squeeze = _kSqueeze,
@required this.itemExtent,
@required this.onSelectedItemChanged,
@required List<Widget> children,
required this.itemExtent,
required this.onSelectedItemChanged,
required List<Widget> children,
bool looping = false,
}) : assert(children != null),
assert(diameterRatio != null),
Expand Down Expand Up @@ -106,7 +106,7 @@ class BrnPicker extends StatefulWidget {
/// disable the background painting entirely; this is mildly more efficient
/// than using [Colors.transparent].
BrnPicker.builder({
Key key,
Key? key,
this.diameterRatio = _kDefaultDiameterRatio,
this.backgroundColor = _kDefaultBackground,
this.lineColor = _kHighlighterBorder,
Expand All @@ -115,10 +115,10 @@ class BrnPicker extends StatefulWidget {
this.magnification = 1.0,
this.scrollController,
this.squeeze = _kSqueeze,
@required this.itemExtent,
@required this.onSelectedItemChanged,
@required IndexedWidgetBuilder itemBuilder,
int childCount,
required this.itemExtent,
required this.onSelectedItemChanged,
required IndexedWidgetBuilder itemBuilder,
int? childCount,
}) : assert(itemBuilder != null),
assert(diameterRatio != null),
assert(diameterRatio > 0.0,
Expand Down Expand Up @@ -153,7 +153,7 @@ class BrnPicker extends StatefulWidget {
final Color backgroundColor;

///分割线颜色
final Color lineColor;
final Color? lineColor;

/// {@macro flutter.rendering.wheelList.offAxisFraction}
final double offAxisFraction;
Expand All @@ -167,7 +167,7 @@ class BrnPicker extends StatefulWidget {
/// A [FixedExtentScrollController] to read and control the current item.
///
/// If null, an implicit one will be created internally.
final FixedExtentScrollController scrollController;
final FixedExtentScrollController? scrollController;

/// The uniform height of all children.
///
Expand Down Expand Up @@ -197,8 +197,8 @@ class BrnPicker extends StatefulWidget {
}

class _CupertinoPickerState extends State<BrnPicker> {
int _lastHapticIndex;
FixedExtentScrollController _controller;
int? _lastHapticIndex;
FixedExtentScrollController? _controller;

@override
void initState() {
Expand Down Expand Up @@ -249,8 +249,7 @@ class _CupertinoPickerState extends State<BrnPicker> {
if (widget.backgroundColor != null && widget.backgroundColor.alpha < 255)
return Container();

final Color widgetBackgroundColor =
widget.backgroundColor ?? const Color(0xFFFFFFFF);
final Color widgetBackgroundColor = widget.backgroundColor;
return Positioned.fill(
child: IgnorePointer(
child: Container(
Expand Down Expand Up @@ -288,7 +287,7 @@ class _CupertinoPickerState extends State<BrnPicker> {
/// Makes the magnifier lens look so that the colors are normal through
/// the lens and partially grayed out around it.
Widget _buildMagnifierScreen() {
final Color foreground = widget.backgroundColor?.withAlpha(
final Color foreground = widget.backgroundColor.withAlpha(
(widget.backgroundColor.alpha * _kForegroundScreenOpacityFraction)
.toInt());

Expand Down Expand Up @@ -326,7 +325,7 @@ class _CupertinoPickerState extends State<BrnPicker> {
}

Widget _buildUnderMagnifierScreen() {
final Color foreground = widget.backgroundColor?.withAlpha(
final Color foreground = widget.backgroundColor.withAlpha(
(widget.backgroundColor.alpha * _kForegroundScreenOpacityFraction)
.toInt());

Expand Down Expand Up @@ -361,7 +360,7 @@ class _CupertinoPickerState extends State<BrnPicker> {
children: <Widget>[
Positioned.fill(
child: _CupertinoPickerSemantics(
scrollController: widget.scrollController ?? _controller,
scrollController: widget.scrollController ?? _controller!,
child: ListWheelScrollView.useDelegate(
controller: widget.scrollController ?? _controller,
hexintao marked this conversation as resolved.
Show resolved Hide resolved
physics: const FixedExtentScrollPhysics(),
Expand Down Expand Up @@ -406,9 +405,9 @@ class _CupertinoPickerState extends State<BrnPicker> {
// scroll controller.
class _CupertinoPickerSemantics extends SingleChildRenderObjectWidget {
const _CupertinoPickerSemantics({
Key key,
Widget child,
@required this.scrollController,
Key? key,
Widget? child,
required this.scrollController,
}) : super(key: key, child: child);

final FixedExtentScrollController scrollController;
Expand All @@ -433,16 +432,16 @@ class _RenderCupertinoPickerSemantics extends RenderProxyBox {
this.controller = controller;
}

FixedExtentScrollController get controller => _controller;
FixedExtentScrollController _controller;
FixedExtentScrollController? get controller => _controller;
FixedExtentScrollController? _controller;

set controller(FixedExtentScrollController value) {
set controller(FixedExtentScrollController? value) {
if (value == _controller) return;
if (_controller != null)
_controller.removeListener(_handleScrollUpdate);
_controller!.removeListener(_handleScrollUpdate);
else
_currentIndex = value.initialItem ?? 0;
value.addListener(_handleScrollUpdate);
_currentIndex = value!.initialItem;
violinday marked this conversation as resolved.
Show resolved Hide resolved
value!.addListener(_handleScrollUpdate);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

但是这里是在else外的,需要加?,发现了这个问题

_controller = value;
}

Expand All @@ -458,17 +457,17 @@ class _RenderCupertinoPickerSemantics extends RenderProxyBox {
int _currentIndex = 0;

void _handleIncrease() {
controller.jumpToItem(_currentIndex + 1);
controller!.jumpToItem(_currentIndex + 1);
}

void _handleDecrease() {
if (_currentIndex == 0) return;
controller.jumpToItem(_currentIndex - 1);
controller!.jumpToItem(_currentIndex - 1);
}

void _handleScrollUpdate() {
if (controller.selectedItem == _currentIndex) return;
_currentIndex = controller.selectedItem;
if (controller!.selectedItem == _currentIndex) return;
_currentIndex = controller!.selectedItem;
markNeedsSemanticsUpdate();
}

Expand All @@ -485,7 +484,7 @@ class _RenderCupertinoPickerSemantics extends RenderProxyBox {
if (children.isEmpty)
return super.assembleSemanticsNode(node, config, children);
final SemanticsNode scrollable = children.first;
final Map<int, SemanticsNode> indexedChildren = <int, SemanticsNode>{};
final Map<int?, SemanticsNode> indexedChildren = <int?, SemanticsNode>{};
scrollable.visitChildren((SemanticsNode child) {
assert(child.indexInParent != null);
indexedChildren[child.indexInParent] = child;
Expand All @@ -494,9 +493,9 @@ class _RenderCupertinoPickerSemantics extends RenderProxyBox {
if (indexedChildren[_currentIndex] == null) {
return node.updateWith(config: config);
}
config.value = indexedChildren[_currentIndex].label;
final SemanticsNode previousChild = indexedChildren[_currentIndex - 1];
final SemanticsNode nextChild = indexedChildren[_currentIndex + 1];
config.value = indexedChildren[_currentIndex]!.label;
final SemanticsNode? previousChild = indexedChildren[_currentIndex - 1];
final SemanticsNode? nextChild = indexedChildren[_currentIndex + 1];
if (nextChild != null) {
config.increasedValue = nextChild.label;
config.onIncrease = _handleIncrease;
Expand Down
14 changes: 7 additions & 7 deletions lib/src/components/picker/base/brn_picker_constants.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import 'package:flutter/material.dart';

/// Default value of DatePicker's item [TextStyle].
const TextStyle DATETIME_PICKER_ITEM_TEXT_STYLE = TextStyle(
const TextStyle datetimePickerItemTextStyle = TextStyle(
color: Color(0xFF222222),
fontSize: 18.0,
);

/// Default value of DatePicker's background color.
const PICKER_BACKGROUND_COLOR = Colors.white;
const pickerBackgroundColor = Colors.white;

/// Default value of whether show title widget or not.
const PICKER_SHOW_TITLE_DEFAULT = true;
const pickerShowTitleDefault = true;

/// Default value of DatePicker's height.
const double PICKER_HEIGHT = 240.0;
const double pickerHeight = 240.0;

/// Default value of DatePicker's title height.
const double PICKER_TITLE_HEIGHT = 48.0;
const double pickerTitleHeight = 48.0;

/// Default value of DatePicker's column height.
const double PICKER_ITEM_HEIGHT = 48.0;
const double pickerItemHeight = 48.0;

/// Default value of DatePicker's item [TextStyle].
const TextStyle PICKER_ITEM_TEXT_STYLE = TextStyle(
const TextStyle pickerItemTextStyle = TextStyle(
color: Color(0xFF222222),
fontSize: 18.0,
);
Loading