Skip to content

Commit

Permalink
migrate picker to null safety (#91)
Browse files Browse the repository at this point in the history
* Theme: 优化单例实现,初步优化 BrnAllThemeConfig 属性获取不为 null

* refactor:优化theme,暴露非null引用

* theme:去除无用信息及优化部分代码

* theme:增加属性类型

* 优化修复 EventBus

* 迁移example ,优化常量命名,增加export

* migrate brn_empty_status.dart

* 删除 BrnThemeImg

* fix:tagConfig merge方法增加判空处理

* fix:revert tagConfig

* fix:BrnAbnormalStateWidget空处理

* Migrated tabbar to null-safety

* Migrated scroll_anchor to null-safety

* fix:修复迁移tabar问题

* migrate form to null safety

* fix:修复tabbar报错及selection警告信息

* fix:修复迁移问题

* fix:优化迁移部分问题key和style非空问题

* migrate picker to null safety

* fix:修复picker空安全迁移问题

* fix:修复list没指定泛型及if判断错误问题

* fix:migrate dashed line to null safty
  • Loading branch information
zhoujuanjuan authored Jan 26, 2022
1 parent 49e9147 commit a4c1a74
Show file tree
Hide file tree
Showing 39 changed files with 1,099 additions and 1,140 deletions.
4 changes: 2 additions & 2 deletions example/lib/sample/components/line/dashed_line_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _DashedLineExampleState extends State<DashedLineExample> {
axis: Axis.vertical,
color: Colors.red,
dashedOffset: 20,
position: BrnDashedLinePosition.DashedLineLeading,
position: BrnDashedLinePosition.leading,
contentWidget: Container(
margin: EdgeInsets.only(left: 60, right: 20, top: 10, bottom: 10),
child:
Expand All @@ -56,7 +56,7 @@ class _DashedLineExampleState extends State<DashedLineExample> {
axis: Axis.horizontal,
color: Colors.green,
dashedOffset: 20,
position: BrnDashedLinePosition.DashedLineLeading,
position: BrnDashedLinePosition.leading,
contentWidget: Container(
width: 200,
height: 100,
Expand Down
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
98 changes: 46 additions & 52 deletions lib/src/components/line/brn_dashed_line.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';

Expand All @@ -13,33 +11,29 @@ import 'package:flutter/material.dart';
/// 分割线所在位置
enum BrnDashedLinePosition {
/// 头部
DashedLineTrailing,
trailing,

/// 尾部
DashedLineLeading,
leading,
}

/// 虚线分割线
class BrnDashedLine extends StatelessWidget {
/// 默认虚线方向
static const Axis _normalAxis = Axis.horizontal;
/// 默认虚线方向
const Axis _normalAxis = Axis.horizontal;

/// 默认虚线长度
static const double _normalDashedLength = 8;
/// 默认虚线长度
const double _normalDashedLength = 8;

/// 默认虚线厚度
static const double _normalDashedThickness = 1;
/// 默认虚线厚度
const double _normalDashedThickness = 1;

/// 默认间距
static const double _normalDashedSpacing = 4;
/// 默认间距
const double _normalDashedSpacing = 4;

/// 默认颜色
static Color _normalColor =
BrnThemeConfigurator.instance.getConfig().commonConfig.dividerColorBase;
/// 默认位置,头部
const BrnDashedLinePosition _normalPosition = BrnDashedLinePosition.leading;

/// 默认位置,头部
static const BrnDashedLinePosition _normalPosition =
BrnDashedLinePosition.DashedLineLeading;
/// 虚线分割线
class BrnDashedLine extends StatelessWidget {

/// 虚线方向,默认值[_normalAxis]
final Axis axis;
Expand All @@ -54,7 +48,7 @@ class BrnDashedLine extends StatelessWidget {
final double dashedSpacing;

/// 颜色,默认值[_normalColor]
final Color color;
final Color? color;

/// 虚线的Widget
final Widget contentWidget;
Expand All @@ -66,28 +60,28 @@ class BrnDashedLine extends StatelessWidget {
final BrnDashedLinePosition position;

BrnDashedLine({
Key key,
@required this.contentWidget,
this.axis,
this.dashedLength,
this.dashedThickness,
this.dashedSpacing,
Key? key,
required this.contentWidget,
this.axis = _normalAxis,
this.dashedLength = _normalDashedLength,
this.dashedThickness = _normalDashedThickness,
this.dashedSpacing = _normalDashedSpacing,
this.color,
this.dashedOffset,
this.position,
this.dashedOffset = 0.0,
this.position = _normalPosition,
});

@override
Widget build(BuildContext context) {
return CustomPaint(
painter: BrnDashedPainter(
axis: this.axis ?? _normalAxis,
dashedLength: this.dashedLength ?? _normalDashedLength,
dashedThickness: this.dashedThickness ?? _normalDashedThickness,
dashedSpacing: this.dashedSpacing ?? _normalDashedSpacing,
color: this.color ?? _normalColor,
dashedOffset: this.dashedOffset ?? 0,
position: this.position ?? _normalPosition),
axis: this.axis,
dashedLength: this.dashedLength ,
dashedThickness: this.dashedThickness,
dashedSpacing: this.dashedSpacing ,
color: this.color ,
dashedOffset: this.dashedOffset,
position: this.position),
child: this.contentWidget,
);
}
Expand All @@ -107,30 +101,30 @@ class BrnDashedPainter extends CustomPainter {
final double dashedSpacing;

/// 颜色
final Color color;
final Color? color;

/// 距离边缘的位置
final double dashedOffset;
final double? dashedOffset;

/// 分割线所在位置
final BrnDashedLinePosition position;
final BrnDashedLinePosition? position;

BrnDashedPainter({
this.axis,
this.dashedLength,
this.dashedThickness,
this.dashedSpacing,
this.axis = _normalAxis,
this.dashedLength = _normalDashedLength,
this.dashedThickness = _normalDashedThickness,
this.dashedSpacing = _normalDashedSpacing,
this.color,
this.dashedOffset,
this.position,
this.dashedOffset = 0.0,
this.position = _normalPosition,
});

@override
void paint(Canvas canvas, Size size) {
var paint = Paint() // 创建一个画笔并配置其属性
..strokeWidth = this.dashedThickness // 画笔的宽度
..isAntiAlias = true // 是否抗锯齿
..color = this.color; // 画笔颜色
..color = this.color?? BrnThemeConfigurator.instance.getConfig().commonConfig.dividerColorBase; // 画笔颜色

var maxWidth = size.width; // size获取到宽度
var maxHeight = size.height; // size获取到宽度
Expand All @@ -139,12 +133,12 @@ class BrnDashedPainter extends CustomPainter {
double startX = 0;
final space = (this.dashedSpacing + this.dashedLength);
double height = 0;
if (this.position == BrnDashedLinePosition.DashedLineLeading) {
if (this.position == BrnDashedLinePosition.leading) {
// 头部
height = dashedOffset + this.dashedThickness / 2;
height = dashedOffset! + this.dashedThickness / 2;
} else {
// 尾部
height = size.height - dashedOffset - this.dashedThickness / 2;
height = size.height - dashedOffset! - this.dashedThickness / 2;
}
while (startX < maxWidth) {
if ((maxWidth - startX) < this.dashedLength) {
Expand All @@ -161,12 +155,12 @@ class BrnDashedPainter extends CustomPainter {
double startY = 0;
final space = (this.dashedSpacing + this.dashedLength);
double width = 0;
if (this.position == BrnDashedLinePosition.DashedLineLeading) {
if (this.position == BrnDashedLinePosition.leading) {
// 头部
width = dashedOffset + this.dashedThickness / 2;
width = dashedOffset! + this.dashedThickness / 2;
} else {
// 尾部
width = size.width - dashedOffset - this.dashedThickness / 2;
width = size.width - dashedOffset! - this.dashedThickness / 2;
}
while (startY < maxHeight) {
if ((maxHeight - startY) < this.dashedLength) {
Expand Down
Loading

0 comments on commit a4c1a74

Please sign in to comment.