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 null safety #95

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.2.0] - March 07, 2021
- Migrated to null safety

## [0.1.6] - August 21, 2020

- [Feature #63](https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/issues/63) method callback after individual showcase start and end
Expand Down
7 changes: 3 additions & 4 deletions example/lib/detailscreen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:showcaseview/showcase_widget.dart';
import 'package:showcaseview/showcaseview.dart';

class Detail extends StatefulWidget {
Expand All @@ -9,14 +8,14 @@ class Detail extends StatefulWidget {

class _DetailState extends State<Detail> {
final GlobalKey _one = GlobalKey();
BuildContext myContext;
BuildContext? myContext;

@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
WidgetsBinding.instance!.addPostFrameCallback((_) {
Future.delayed(Duration(milliseconds: 200),
() => ShowCaseWidget.of(myContext).startShowCase([_one]));
() => ShowCaseWidget.of(myContext!)!.startShowCase([_one]));
});
}

Expand Down
18 changes: 9 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class _MailPageState extends State<MailPage> {
void initState() {
super.initState();
//Start showcase view after current widget frames are drawn.
WidgetsBinding.instance.addPostFrameCallback((_) =>
ShowCaseWidget.of(context)
WidgetsBinding.instance!.addPostFrameCallback((_) =>
ShowCaseWidget.of(context)!
.startShowCase([_one, _two, _three, _four, _five]));
}

Expand Down Expand Up @@ -163,7 +163,7 @@ class _MailPageState extends State<MailPage> {
),
).then((_) {
setState(() {
ShowCaseWidget.of(context)
ShowCaseWidget.of(context)!
.startShowCase([_four, _five]);
});
});
Expand Down Expand Up @@ -325,7 +325,7 @@ class _MailPageState extends State<MailPage> {
backgroundColor: Colors.white,
onPressed: () {
setState(() {
ShowCaseWidget.of(context)
ShowCaseWidget.of(context)!
.startShowCase([_one, _two, _three, _four, _five]);
});
},
Expand All @@ -347,11 +347,11 @@ class Mail {
bool isUnread;

Mail({
this.sender,
this.sub,
this.msg,
this.date,
this.isUnread,
required this.sender,
required this.sub,
required this.msg,
required this.date,
required this.isUnread,
});
}

Expand Down
4 changes: 3 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ description: A new Flutter application.
version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

publish_to: none

dependencies:
flutter:
Expand Down
4 changes: 2 additions & 2 deletions lib/showcaseview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@

library showcaseview;

export 'showcase.dart';
export 'showcase_widget.dart';
export 'src/showcase.dart';
export 'src/showcase_widget.dart';
10 changes: 5 additions & 5 deletions lib/custom_paint.dart → lib/src/custom_paint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import 'package:flutter/material.dart';

class ShapePainter extends CustomPainter {
Rect rect;
final ShapeBorder shapeBorder;
final Color color;
final double opacity;
final ShapeBorder? shapeBorder;
final Color? color;
final double? opacity;

ShapePainter({
@required this.rect,
required this.rect,
this.color,
this.shapeBorder,
this.opacity,
Expand All @@ -42,7 +42,7 @@ class ShapePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint();
paint.color = color.withOpacity(opacity);
paint.color = color!.withOpacity(opacity!);
RRect outer =
RRect.fromLTRBR(0, 0, size.width, size.height, Radius.circular(0));

Expand Down
12 changes: 6 additions & 6 deletions lib/get_position.dart → lib/src/get_position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import 'package:flutter/material.dart';

class GetPosition {
final GlobalKey key;
final GlobalKey? key;

GetPosition({this.key});

Rect getRect() {
RenderBox box = key.currentContext.findRenderObject();
RenderBox box = key!.currentContext!.findRenderObject() as RenderBox;

final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
final bottomRight =
Expand All @@ -49,29 +49,29 @@ class GetPosition {

///Get the bottom position of the widget
double getBottom() {
RenderBox box = key.currentContext.findRenderObject();
RenderBox box = key!.currentContext!.findRenderObject() as RenderBox;
final bottomRight =
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
return bottomRight.dy;
}

///Get the top position of the widget
double getTop() {
RenderBox box = key.currentContext.findRenderObject();
RenderBox box = key!.currentContext!.findRenderObject() as RenderBox;
final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
return topLeft.dy;
}

///Get the left position of the widget
double getLeft() {
RenderBox box = key.currentContext.findRenderObject();
RenderBox box = key!.currentContext!.findRenderObject() as RenderBox;
final topLeft = box.size.topLeft(box.localToGlobal(const Offset(0.0, 0.0)));
return topLeft.dx;
}

///Get the right position of the widget
double getRight() {
RenderBox box = key.currentContext.findRenderObject();
RenderBox box = key!.currentContext!.findRenderObject() as RenderBox;
final bottomRight =
box.size.bottomRight(box.localToGlobal(const Offset(0.0, 0.0)));
return bottomRight.dx;
Expand Down
36 changes: 17 additions & 19 deletions lib/layout_overlays.dart → lib/src/layout_overlays.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ import 'package:flutter/material.dart';
///
class AnchoredOverlay extends StatelessWidget {
final bool showOverlay;
final Widget Function(BuildContext, Rect anchorBounds, Offset anchor)
final Widget Function(BuildContext, Rect anchorBounds, Offset anchor)?
overlayBuilder;
final Widget child;
final Widget? child;

AnchoredOverlay({
key,
Expand Down Expand Up @@ -75,7 +75,7 @@ class AnchoredOverlay extends StatelessWidget {
bottomRight.dy,
);
final anchorCenter = box.size.center(topLeft);
return overlayBuilder(overlayContext, anchorBounds, anchorCenter);
return overlayBuilder!(overlayContext, anchorBounds, anchorCenter);
},
child: child,
);
Expand All @@ -99,8 +99,8 @@ class AnchoredOverlay extends StatelessWidget {
//
class OverlayBuilder extends StatefulWidget {
final bool showOverlay;
final Widget Function(BuildContext) overlayBuilder;
final Widget child;
final Widget Function(BuildContext)? overlayBuilder;
final Widget? child;

OverlayBuilder({
key,
Expand All @@ -114,27 +114,29 @@ class OverlayBuilder extends StatefulWidget {
}

class _OverlayBuilderState extends State<OverlayBuilder> {
OverlayEntry _overlayEntry;
OverlayEntry? _overlayEntry;

@override
void initState() {
super.initState();

if (widget.showOverlay) {
WidgetsBinding.instance.addPostFrameCallback((_) => showOverlay());
WidgetsBinding.instance!.addPostFrameCallback((_) => showOverlay());
}
}

@override
void didUpdateWidget(OverlayBuilder oldWidget) {
super.didUpdateWidget(oldWidget);
WidgetsBinding.instance.addPostFrameCallback((_) => syncWidgetAndOverlay());
WidgetsBinding.instance!
.addPostFrameCallback((_) => syncWidgetAndOverlay());
}

@override
void reassemble() {
super.reassemble();
WidgetsBinding.instance.addPostFrameCallback((_) => syncWidgetAndOverlay());
WidgetsBinding.instance!
.addPostFrameCallback((_) => syncWidgetAndOverlay());
}

@override
Expand All @@ -152,26 +154,22 @@ class _OverlayBuilderState extends State<OverlayBuilder> {
if (_overlayEntry == null) {
// Create the overlay.
_overlayEntry = OverlayEntry(
builder: widget.overlayBuilder,
builder: widget.overlayBuilder!,
);
addToOverlay(_overlayEntry);
addToOverlay(_overlayEntry!);
} else {
// Rebuild overlay.
buildOverlay();
}
}

void addToOverlay(OverlayEntry overlayEntry) async {
Overlay.of(context).insert(overlayEntry);
final overlay = Overlay.of(context);
if (overlayEntry == null)
WidgetsBinding.instance
.addPostFrameCallback((_) => overlay.insert(overlayEntry));
Overlay.of(context)!.insert(overlayEntry);
}

void hideOverlay() {
if (_overlayEntry != null) {
_overlayEntry.remove();
_overlayEntry!.remove();
_overlayEntry = null;
}
}
Expand All @@ -185,14 +183,14 @@ class _OverlayBuilderState extends State<OverlayBuilder> {
}

void buildOverlay() async {
WidgetsBinding.instance
WidgetsBinding.instance!
.addPostFrameCallback((_) => _overlayEntry?.markNeedsBuild());
}

@override
Widget build(BuildContext context) {
buildOverlay();

return widget.child;
return widget.child!;
}
}
10 changes: 5 additions & 5 deletions lib/measure_size.dart → lib/src/measure_size.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

typedef OnWidgetSizeChange = void Function(Size size);
typedef OnWidgetSizeChange = void Function(Size? size);

class MeasureSize extends StatefulWidget {
final Widget child;
final Widget? child;
final OnWidgetSizeChange onSizeChange;

MeasureSize({
@required this.onSizeChange,
@required this.child,
required this.onSizeChange,
required this.child,
});

@override
Expand All @@ -19,7 +19,7 @@ class MeasureSize extends StatefulWidget {
class _MeasureSizeState extends State<MeasureSize> {
@override
Widget build(BuildContext context) {
SchedulerBinding.instance.addPostFrameCallback(postFrameCallback);
SchedulerBinding.instance!.addPostFrameCallback(postFrameCallback);
return Container(
key: widgetKey,
child: widget.child,
Expand Down
Loading