Skip to content

Commit

Permalink
Migrated package [guide] to null-safety (#65)
Browse files Browse the repository at this point in the history
* reset and migrated package [rating] to null-safety.

* Migrated package [selectcity] to null-safety

* 修改ISuspensionBean抽象类相关子类的空字段问题。

* Migrated package [noticebar] to null-safety

* 1.Migrated package [radio] to null-safety;
2.Modified not-need-nullable param in brn_single_select_city_page.dart;

* Migrated package [guide] to null-safety
  • Loading branch information
jojinshallar authored Jan 12, 2022
1 parent 232f347 commit fc0579a
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 105 deletions.
12 changes: 5 additions & 7 deletions lib/src/components/guide/brn_delay_rendered_widget.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

part of brn_intro;

/// 延时渲染一个 Widget
Expand All @@ -17,10 +15,10 @@ class _DelayRenderedWidget extends StatefulWidget {
final bool removed;

const _DelayRenderedWidget({
Key key,
Key? key,
this.removed = false,
this.duration = const Duration(milliseconds: 200),
this.child,
required this.child,
this.childPersist = false,
}) : super(key: key);

Expand All @@ -30,8 +28,8 @@ class _DelayRenderedWidget extends StatefulWidget {

class _DelayRenderedWidgetState extends State<_DelayRenderedWidget> {
double opacity = 0;
Widget child;
Timer timer;
late Widget child;
late Timer timer;

/// Time interval between animations
final Duration durationInterval = Duration(milliseconds: 100);
Expand All @@ -51,8 +49,8 @@ class _DelayRenderedWidgetState extends State<_DelayRenderedWidget> {

@override
void dispose() {
super.dispose();
timer.cancel();
super.dispose();
}

@override
Expand Down
76 changes: 35 additions & 41 deletions lib/src/components/guide/brn_flutter_guide.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

library brn_intro;

import 'dart:async';
Expand Down Expand Up @@ -34,18 +32,18 @@ class BrnTipInfoBean {
/// 支持 强引导:界面变灰,引导框高亮| 弱引导:直接在界面浮现提示框两种
class BrnGuide {
bool _removed = false;
double _widgetWidth;
double _widgetHeight;
Offset _widgetOffset;
OverlayEntry _overlayEntry;
late double _widgetWidth;
late double _widgetHeight;
late Offset _widgetOffset;
OverlayEntry? _overlayEntry;
int _currentStepIndex = 0;
Widget _stepWidget;
late Widget _stepWidget;
List<Map> _configMap = [];
List<GlobalKey> _globalKeys = [];
final Color _maskColor = Colors.black.withOpacity(.6);
final Duration _animationDuration = Duration(milliseconds: 300);
final _th = _Throttling(duration: Duration(milliseconds: 500));
Size _lastScreenSize;
late Size _lastScreenSize;

/// 当前处于第几步
int get currentStepIndex => _currentStepIndex;
Expand All @@ -63,15 +61,15 @@ class BrnGuide {
final int stepCount;

/// 每次点击的下一步的时候的回调
final void Function(int nextIndex) onNextClick;
final void Function(int nextIndex)? onNextClick;

/// 引导交互的模式
GuideMode introMode;

BrnGuide(
{@required this.introMode,
@required this.widgetBuilder,
@required this.stepCount,
{required this.introMode,
required this.widgetBuilder,
required this.stepCount,
this.borderRadius = const BorderRadius.all(Radius.circular(4)),
this.padding = const EdgeInsets.all(10),
this.onNextClick})
Expand All @@ -91,8 +89,8 @@ class BrnGuide {
/// [borderRadius] BorderRadius setting
void setStepConfig(
int stepIndex, {
EdgeInsets padding,
BorderRadiusGeometry borderRadius,
EdgeInsets? padding,
BorderRadiusGeometry? borderRadius,
}) {
assert(stepIndex >= 0 && stepIndex < stepCount);
_configMap[stepIndex] = {
Expand All @@ -108,8 +106,8 @@ class BrnGuide {
/// [borderRadius] BorderRadius setting
void setStepsConfig(
List<int> stepsIndex, {
EdgeInsets padding,
BorderRadiusGeometry borderRadius,
EdgeInsets? padding,
BorderRadiusGeometry? borderRadius,
}) {
assert(stepsIndex
.every((stepIndex) => stepIndex >= 0 && stepIndex < stepCount));
Expand All @@ -124,9 +122,9 @@ class BrnGuide {

void _getWidgetInfo(GlobalKey globalKey) {
try {
EdgeInsets currentConfig = _configMap[_currentStepIndex]['padding'];
RenderBox renderBox;
renderBox = globalKey.currentContext.findRenderObject();
EdgeInsets? currentConfig = _configMap[_currentStepIndex]['padding'];
RenderBox renderBox =
globalKey.currentContext?.findRenderObject() as RenderBox;
_widgetWidth = renderBox.size.width +
(currentConfig?.horizontal ?? padding.horizontal);
_widgetHeight =
Expand All @@ -141,20 +139,20 @@ class BrnGuide {
_widgetWidth = 0;
_widgetHeight = 0;
_widgetOffset = Offset.zero;
debugPrint('获取组件尺寸信息异常');
debugPrint('获取组件尺寸信息异常${e.toString()}');
}
}

Widget _maskBuilder({
double width,
double height,
BlendMode backgroundBlendMode,
@required double left,
@required double top,
double bottom,
double right,
BorderRadiusGeometry borderRadiusGeometry,
Widget child,
double? width,
double? height,
BlendMode? backgroundBlendMode,
required double left,
required double top,
double? bottom,
double? right,
BorderRadiusGeometry? borderRadiusGeometry,
Widget? child,
}) {
final decoration = BoxDecoration(
color: Colors.white,
Expand Down Expand Up @@ -191,7 +189,7 @@ class BrnGuide {
_lastScreenSize = screenSize;
_th.throttle(() {
_createStepWidget(context);
_overlayEntry.markNeedsBuild();
_overlayEntry?.markNeedsBuild();
});
}

Expand Down Expand Up @@ -241,14 +239,14 @@ class BrnGuide {
);
},
);
Overlay.of(context).insert(_overlayEntry);
Overlay.of(context)?.insert(_overlayEntry!);
}

void _onNext(BuildContext context) {
_currentStepIndex++;
if (_currentStepIndex < stepCount) {
if (onNextClick != null) {
onNextClick(currentStepIndex);
onNextClick!(currentStepIndex);
}
_renderStep(context);
}
Expand All @@ -257,9 +255,9 @@ class BrnGuide {
void _onFinish() {
if (_overlayEntry == null) return;
_removed = true;
_overlayEntry.markNeedsBuild();
_overlayEntry!.markNeedsBuild();
Timer(_animationDuration, () {
_overlayEntry.remove();
_overlayEntry?.remove();
_overlayEntry = null;
});
}
Expand All @@ -274,12 +272,8 @@ class BrnGuide {
screenSize: screenSize,
size: widgetSize,
onNext: _currentStepIndex == stepCount - 1
? () {
_onFinish();
}
: () {
_onNext(context);
},
? () => _onFinish()
: () => _onNext(context),
offset: _widgetOffset,
currentStepIndex: _currentStepIndex,
stepCount: stepCount,
Expand All @@ -289,7 +283,7 @@ class BrnGuide {

void _renderStep(BuildContext context) {
_createStepWidget(context);
if (_overlayEntry != null) _overlayEntry.markNeedsBuild();
_overlayEntry?.markNeedsBuild();
}

/// 触发引导操作 [context]当前环境[BuildContext]的启动方法
Expand Down
11 changes: 5 additions & 6 deletions lib/src/components/guide/brn_pulse_widget.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 @@ -8,17 +6,18 @@ class PulseWidget extends StatefulWidget {
final double width;
final double height;

const PulseWidget({Key key, this.width, this.height}) : super(key: key);
const PulseWidget({Key? key, required this.width, required this.height})
: super(key: key);

@override
_PulseWidgetState createState() => _PulseWidgetState();
}

class _PulseWidgetState extends State<PulseWidget>
with TickerProviderStateMixin {
AnimationController _scaleController;
AnimationController _fadeController;
Animation _alphaAnimation;
late AnimationController _scaleController;
late AnimationController _fadeController;
late Animation<double> _alphaAnimation;

@override
void initState() {
Expand Down
11 changes: 6 additions & 5 deletions lib/src/components/guide/brn_step_widget_builder.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.9

part of brn_intro;

/// 引导组件所处的方位
Expand All @@ -8,7 +6,10 @@ enum GuideDirection { left, right, topLeft, bottomLeft, topRight, bottomRight }
/// 单步引导组件
class StepWidgetBuilder {
static Map _smartGetPosition(
{Size size, Size screenSize, Offset offset, GuideMode introMode}) {
{required Size size,
required Size screenSize,
required Offset offset,
required GuideMode introMode}) {
double height = size.height;
double width = size.width;
double screenWidth = screenSize.width;
Expand Down Expand Up @@ -166,8 +167,8 @@ class StepWidgetBuilder {
//showSkipLabel表示是否展示跳过按钮
//showClose表示是否展示关闭按钮
static Widget Function(StepWidgetParams params) useDefaultTheme(
{@required List<BrnTipInfoBean> tipInfo,
String Function(int currentStepIndex, int stepCount) buttonTextBuilder,
{required List<BrnTipInfoBean> tipInfo,
String Function(int currentStepIndex, int stepCount)? buttonTextBuilder,
bool showStepLabel = true,
bool showSkipLabel = true,
bool showClose = true}) {
Expand Down
22 changes: 10 additions & 12 deletions lib/src/components/guide/brn_step_widget_params.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
// @dart=2.9

part of brn_intro;

/// Highlight component parameters
class WidgetParams {
/// Padding of highlighted area
EdgeInsets padding;
EdgeInsets? padding;

/// Border radius of the highlighted area
BorderRadiusGeometry borderRadius;
BorderRadiusGeometry? borderRadius;
}

/// The data passed in when the system calls [GuideStep.widgetBuilder] when the guide page is generated
///
class StepWidgetParams {
/// Enter the next guide page method, or null if there is no
final VoidCallback onNext;
final VoidCallback? onNext;

/// End all guide page methods
final VoidCallback onFinish;
final VoidCallback? onFinish;

/// Which guide page is currently displayed, starting from 0
final int currentStepIndex;
Expand All @@ -37,14 +35,14 @@ class StepWidgetParams {
final GuideMode introMode;

StepWidgetParams({
this.introMode,
required this.introMode,
this.onNext,
this.onFinish,
@required this.screenSize,
@required this.size,
@required this.currentStepIndex,
@required this.stepCount,
@required this.offset,
required this.screenSize,
required this.size,
required this.currentStepIndex,
required this.stepCount,
required this.offset,
});

@override
Expand Down
8 changes: 3 additions & 5 deletions lib/src/components/guide/brn_throttling.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// @dart=2.9

part of brn_intro;

/// Throttling
/// Have method [throttle]
class _Throttling {
Duration _duration;
Timer _timer;
late Duration _duration;
Timer? _timer;

_Throttling({Duration duration = const Duration(seconds: 1)})
: assert(duration is Duration && !duration.isNegative) {
: assert(!duration.isNegative) {
_duration = duration;
}

Expand Down
Loading

0 comments on commit fc0579a

Please sign in to comment.