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

Added positioned widget to the overlay so that the overlay wont take up the entire space on the screen #37

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
40 changes: 9 additions & 31 deletions example/lib/custom_toast_content_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class IconToastWidget extends StatelessWidget {
this.message,
this.height,
this.width,
@required this.assetName,
required this.assetName,
this.padding,
});

Expand All @@ -47,8 +47,7 @@ class IconToastWidget extends StatelessWidget {
color: Colors.transparent,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 50.0),
padding:
padding ?? EdgeInsets.symmetric(vertical: 20.0, horizontal: 17.0),
padding: padding ?? EdgeInsets.symmetric(vertical: 20.0, horizontal: 17.0),
decoration: ShapeDecoration(
color: backgroundColor ?? const Color(0x9F000000),
shape: RoundedRectangleBorder(
Expand All @@ -73,10 +72,7 @@ class IconToastWidget extends StatelessWidget {
child: textWidget ??
Text(
message ?? '',
style: TextStyle(
fontSize:
Theme.of(context).textTheme.titleLarge!.fontSize,
color: Colors.white),
style: TextStyle(fontSize: Theme.of(context).textTheme.titleLarge!.fontSize, color: Colors.white),
softWrap: true,
maxLines: 200,
),
Expand All @@ -89,14 +85,6 @@ class IconToastWidget extends StatelessWidget {
}
}

///
///created time: 2019-06-17 16:22
///author linzhiliang
///version 1.5.0
///since
///file name: styled_toast.dart
///description: Banner type toast widget, example of custom toast content widget when you use [showToastWidget]
///
class BannerToastWidget extends StatelessWidget {
final Color? backgroundColor;
final String? message;
Expand All @@ -115,22 +103,14 @@ class BannerToastWidget extends StatelessWidget {
final double? offset,
}) : this.offset = (offset == null ? 10.0 : offset);

factory BannerToastWidget.success(
{String? msg, Widget? text, BuildContext? context}) =>
BannerToastWidget(
backgroundColor: context != null
? Theme.of(context).toggleButtonsTheme.fillColor
: Colors.green,
factory BannerToastWidget.success({String? msg, Widget? text, BuildContext? context}) => BannerToastWidget(
backgroundColor: context != null ? Theme.of(context).toggleButtonsTheme.fillColor : Colors.green,
message: msg,
textWidget: text,
);

factory BannerToastWidget.fail(
{String? msg, Widget? text, BuildContext? context}) =>
BannerToastWidget(
backgroundColor: context != null
? Theme.of(context).colorScheme.error
: const Color(0xEFCC2E2E),
factory BannerToastWidget.fail({String? msg, Widget? text, BuildContext? context}) => BannerToastWidget(
backgroundColor: context != null ? Theme.of(context).colorScheme.error : const Color(0xEFCC2E2E),
message: msg,
textWidget: text,
);
Expand All @@ -142,13 +122,11 @@ class BannerToastWidget extends StatelessWidget {
padding: EdgeInsets.all(17.0),
height: 60.0,
alignment: Alignment.center,
color: backgroundColor ?? Theme.of(context).colorScheme.background,
color: backgroundColor ?? Theme.of(context).colorScheme.surface,
child: textWidget ??
Text(
message ?? '',
style: TextStyle(
fontSize: Theme.of(context).textTheme.titleLarge!.fontSize,
color: Colors.white),
style: TextStyle(fontSize: Theme.of(context).textTheme.titleLarge!.fontSize, color: Colors.white),
),
);

Expand Down
1 change: 1 addition & 0 deletions lib/flutter_styled_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export 'src/styled_toast_manage.dart';
export 'src/custom_size_transition.dart';
export 'src/custom_animation.dart';
export 'src/styled_toast_theme.dart';
export 'src/position_model.dart';
17 changes: 17 additions & 0 deletions lib/src/position_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class OverlayPosition {
final double? left;
final double? top;
final double? right;
final double? bottom;
final double? width;
final double? height;

const OverlayPosition({
this.left,
this.top,
this.right,
this.bottom,
this.width,
this.height,
});
}
60 changes: 35 additions & 25 deletions lib/src/styled_toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'custom_size_transition.dart';
import 'styled_toast_enum.dart';
import 'styled_toast_manage.dart';
import 'styled_toast_theme.dart';
import 'position_model.dart';

/// Current context of the page which uses the toast.
BuildContext? currentContext;
Expand Down Expand Up @@ -164,6 +165,7 @@ ToastFuture showToastWidget(
CustomAnimationBuilder? reverseAnimBuilder,
bool? isIgnoring,
OnInitStateCallback? onInitState,
OverlayPosition? overlayPosition,
}) {
OverlayEntry entry;
ToastFuture future;
Expand Down Expand Up @@ -227,31 +229,39 @@ ToastFuture showToastWidget(
GlobalKey<StyledToastWidgetState> key = GlobalKey();

entry = OverlayEntry(builder: (ctx) {
return IgnorePointer(
ignoring: isIgnoring!,
child: _StyledToastWidget(
duration: duration!,
animDuration: animDuration!,
position: position,
animation: animation,
reverseAnimation: reverseAnimation,
alignment: alignment,
axis: axis,
startOffset: startOffset,
endOffset: endOffset,
reverseStartOffset: reverseStartOffset,
reverseEndOffset: reverseEndOffset,
curve: curve!,
reverseCurve: reverseCurve!,
key: key,
animationBuilder: animationBuilder,
reverseAnimBuilder: reverseAnimBuilder,
onInitState: onInitState,
child: Directionality(
textDirection: textDirection!,
child: Material(
child: widget,
color: Colors.transparent,
return Positioned(
top: overlayPosition?.top,
bottom: overlayPosition?.bottom,
left: overlayPosition?.left,
right: overlayPosition?.right,
height: overlayPosition?.height,
width: overlayPosition?.width,
child: IgnorePointer(
ignoring: isIgnoring!,
child: _StyledToastWidget(
duration: duration!,
animDuration: animDuration!,
position: position,
animation: animation,
reverseAnimation: reverseAnimation,
alignment: alignment,
axis: axis,
startOffset: startOffset,
endOffset: endOffset,
reverseStartOffset: reverseStartOffset,
reverseEndOffset: reverseEndOffset,
curve: curve!,
reverseCurve: reverseCurve!,
key: key,
animationBuilder: animationBuilder,
reverseAnimBuilder: reverseAnimBuilder,
onInitState: onInitState,
child: Directionality(
textDirection: textDirection!,
child: Material(
child: widget,
color: Colors.transparent,
),
),
),
),
Expand Down