-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add examples to custom modal types
- Loading branch information
Showing
17 changed files
with
483 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
playground/lib/home/custom_sheets/floating_bottom_sheet_type.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; | ||
|
||
class FloatingBottomSheetType extends WoltModalType { | ||
final EdgeInsetsDirectional padding; | ||
static const Duration _defaultEnterDuration = Duration(milliseconds: 350); | ||
static const Duration _defaultExitDuration = Duration(milliseconds: 300); | ||
|
||
const FloatingBottomSheetType({ | ||
this.padding = const EdgeInsetsDirectional.all(16.0), | ||
}) : super( | ||
shapeBorder: const RoundedRectangleBorder( | ||
borderRadius: BorderRadius.all(Radius.circular(28.0)), | ||
), | ||
showDragHandle: false, | ||
dismissDirection: WoltModalDismissDirection.down, | ||
transitionDuration: _defaultEnterDuration, | ||
reverseTransitionDuration: _defaultExitDuration, | ||
); | ||
|
||
@override | ||
String routeLabel(BuildContext context) { | ||
final MaterialLocalizations localizations = MaterialLocalizations.of(context); | ||
return localizations.bottomSheetLabel; | ||
} | ||
|
||
@override | ||
BoxConstraints layoutModal(Size availableSize) { | ||
const padding = 32.0; | ||
final availableWidth = availableSize.width; | ||
double width = availableWidth > 523.0 ? 312.0 : availableWidth - padding; | ||
|
||
if (availableWidth > 523.0) { | ||
width = 312.0; | ||
} else if (availableWidth > 240.0) { | ||
width = 240.0; | ||
} else { | ||
width = availableWidth * 0.7; | ||
} | ||
|
||
return BoxConstraints( | ||
minWidth: width, | ||
maxWidth: width, | ||
minHeight: 0, | ||
maxHeight: availableSize.height * 0.8, | ||
); | ||
} | ||
@override | ||
Offset positionModal(Size availableSize, Size modalContentSize, TextDirection textDirection) { | ||
return Offset( | ||
availableSize.width - modalContentSize.width - padding.end, | ||
availableSize.height - modalContentSize.height - padding.bottom, | ||
); | ||
} | ||
|
||
@override | ||
Widget buildTransitions( | ||
BuildContext context, | ||
Animation<double> animation, | ||
Animation<double> secondaryAnimation, | ||
Widget child, | ||
) { | ||
final alphaAnimation = Tween<double>( | ||
begin: 0.0, | ||
end: 1.0, | ||
).animate(CurvedAnimation( | ||
parent: animation, | ||
curve: const Interval(0.0, 100.0 / 300.0, curve: Curves.linear), | ||
reverseCurve: const Interval(100.0 / 250.0, 1.0, curve: Curves.linear), | ||
)); | ||
|
||
final slideAnimation = Tween<Offset>( | ||
begin: const Offset(1, 1), | ||
end: Offset.zero, | ||
).animate(CurvedAnimation( | ||
parent: animation, | ||
curve: Curves.easeInOutCubic, | ||
)); | ||
|
||
final scaleAnimation = Tween<double>( | ||
begin: 0.0, | ||
end: 1.0, | ||
).animate(CurvedAnimation( | ||
parent: animation, | ||
curve: Curves.easeInOutCubic, | ||
)); | ||
|
||
return FadeTransition( | ||
opacity: alphaAnimation, | ||
child: SlideTransition( | ||
position: slideAnimation, | ||
child: ScaleTransition( | ||
scale: scaleAnimation, | ||
child: child, | ||
), | ||
), | ||
); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
playground/lib/home/custom_sheets/top_notification_sheet_type.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; | ||
|
||
class TopNotificationSheetType extends WoltModalType { | ||
final EdgeInsetsDirectional padding; | ||
|
||
const TopNotificationSheetType({ | ||
this.padding = const EdgeInsetsDirectional.all(32.0), | ||
}) : super( | ||
shapeBorder: const RoundedRectangleBorder( | ||
borderRadius: BorderRadius.all(Radius.circular(24)), | ||
), | ||
dismissDirection: WoltModalDismissDirection.up, | ||
showDragHandle: false, | ||
); | ||
|
||
@override | ||
String routeLabel(BuildContext context) { | ||
final MaterialLocalizations localizations = MaterialLocalizations.of(context); | ||
return localizations.dialogLabel; | ||
} | ||
|
||
@override | ||
BoxConstraints layoutModal(Size availableSize) { | ||
final availableWidth = availableSize.width; | ||
double width = availableWidth > 523.0 ? 312.0 : availableWidth - padding.end; | ||
|
||
if (availableWidth > 523.0) { | ||
width = 312.0; | ||
} else if (availableWidth > 240.0) { | ||
width = 240.0; | ||
} else { | ||
width = availableWidth - padding.end; | ||
} | ||
return BoxConstraints( | ||
minWidth: width, | ||
maxWidth: width, | ||
minHeight: 0, | ||
maxHeight: availableSize.height * 0.6, | ||
); | ||
} | ||
|
||
@override | ||
Offset positionModal(Size availableSize, Size modalContentSize, TextDirection textDirection) { | ||
final xOffset = max(0.0, (availableSize.width - modalContentSize.width) / 2); | ||
final yOffset = padding.top; | ||
return Offset(xOffset, yOffset); | ||
} | ||
|
||
@override | ||
Widget buildTransitions( | ||
BuildContext context, | ||
Animation<double> animation, | ||
Animation<double> secondaryAnimation, | ||
Widget child, | ||
) { | ||
final alphaAnimation = Tween<double>( | ||
begin: 0.0, | ||
end: 1.0, | ||
).animate(CurvedAnimation( | ||
parent: animation, | ||
curve: const Interval(0.0, 100.0 / 300.0, curve: Curves.linear), | ||
reverseCurve: const Interval(100.0 / 250.0, 1.0, curve: Curves.linear), | ||
)); | ||
|
||
return FadeTransition( | ||
opacity: alphaAnimation, | ||
child: SlideTransition( | ||
position: animation.drive( | ||
Tween( | ||
begin: const Offset(0.0, -1.0), | ||
end: Offset.zero, | ||
).chain(CurveTween(curve: Curves.easeOutQuad)), | ||
), | ||
child: child, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.