Created
September 11, 2019 19:54
-
-
Save adityadroid/79da87a8ac3678dca49b69a49709caf4 to your computer and use it in GitHub Desktop.
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
//Flutter Modal Bottom Sheet | |
//Modified by Suvadeep Das | |
//Based on https://gist.github.com/andrelsmoraes/9e4af0133bff8960c1feeb0ead7fd749 | |
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:meta/meta.dart'; | |
const Duration _kBottomSheetDuration = const Duration(milliseconds: 200); | |
class _ModalBottomSheetLayout extends SingleChildLayoutDelegate { | |
_ModalBottomSheetLayout(this.progress, this.bottomInset); | |
final double progress; | |
final double bottomInset; | |
@override | |
BoxConstraints getConstraintsForChild(BoxConstraints constraints) { | |
return new BoxConstraints( | |
minWidth: constraints.maxWidth, | |
maxWidth: constraints.maxWidth, | |
minHeight: 0.0, | |
maxHeight: constraints.maxHeight | |
); | |
} | |
@override | |
Offset getPositionForChild(Size size, Size childSize) { | |
return new Offset(0.0, size.height - bottomInset - childSize.height * progress); | |
} | |
@override | |
bool shouldRelayout(_ModalBottomSheetLayout oldDelegate) { | |
return progress != oldDelegate.progress || bottomInset != oldDelegate.bottomInset; | |
} | |
} | |
class _ModalBottomSheet<T> extends StatefulWidget { | |
const _ModalBottomSheet({ Key key, this.route }) : super(key: key); | |
final _ModalBottomSheetRoute<T> route; | |
@override | |
_ModalBottomSheetState<T> createState() => new _ModalBottomSheetState<T>(); | |
} | |
class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | |
@override | |
Widget build(BuildContext context) { | |
return new GestureDetector( | |
onTap: widget.route.dismissOnTap ? () => Navigator.pop(context) : null, | |
child: new AnimatedBuilder( | |
animation: widget.route.animation, | |
builder: (BuildContext context, Widget child) { | |
double bottomInset = widget.route.resizeToAvoidBottomPadding | |
? MediaQuery.of(context).viewInsets.bottom : 0.0; | |
return new ClipRect( | |
child: new CustomSingleChildLayout( | |
delegate: new _ModalBottomSheetLayout(widget.route.animation.value, bottomInset), | |
child: new BottomSheet( | |
animationController: widget.route._animationController, | |
onClosing: () => Navigator.pop(context), | |
builder: widget.route.builder | |
) | |
) | |
); | |
} | |
) | |
); | |
} | |
} | |
class _ModalBottomSheetRoute<T> extends PopupRoute<T> { | |
_ModalBottomSheetRoute({ | |
this.builder, | |
this.theme, | |
this.barrierLabel, | |
RouteSettings settings, | |
this.resizeToAvoidBottomPadding, | |
this.dismissOnTap, | |
}) : super(settings: settings); | |
final WidgetBuilder builder; | |
final ThemeData theme; | |
final bool resizeToAvoidBottomPadding; | |
final bool dismissOnTap; | |
@override | |
Duration get transitionDuration => _kBottomSheetDuration; | |
@override | |
bool get barrierDismissible => false; | |
@override | |
final String barrierLabel; | |
@override | |
Color get barrierColor => Colors.black54; | |
AnimationController _animationController; | |
@override | |
AnimationController createAnimationController() { | |
assert(_animationController == null); | |
_animationController = BottomSheet.createAnimationController(navigator.overlay); | |
return _animationController; | |
} | |
@override | |
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) { | |
// By definition, the bottom sheet is aligned to the bottom of the page | |
// and isn't exposed to the top padding of the MediaQuery. | |
Widget bottomSheet = new MediaQuery.removePadding( | |
context: context, | |
removeTop: true, | |
child: new _ModalBottomSheet<T>(route: this), | |
); | |
if (theme != null) | |
bottomSheet = new Theme(data: theme, child: bottomSheet); | |
return bottomSheet; | |
} | |
} | |
/// Shows a modal material design bottom sheet. | |
/// | |
/// A modal bottom sheet is an alternative to a menu or a dialog and prevents | |
/// the user from interacting with the rest of the app. | |
/// | |
/// A closely related widget is a persistent bottom sheet, which shows | |
/// information that supplements the primary content of the app without | |
/// preventing the use from interacting with the app. Persistent bottom sheets | |
/// can be created and displayed with the [showBottomSheet] function or the | |
/// [ScaffoldState.showBottomSheet] method. | |
/// | |
/// The `context` argument is used to look up the [Navigator] and [Theme] for | |
/// the bottom sheet. It is only used when the method is called. Its | |
/// corresponding widget can be safely removed from the tree before the bottom | |
/// sheet is closed. | |
/// | |
/// Returns a `Future` that resolves to the value (if any) that was passed to | |
/// [Navigator.pop] when the modal bottom sheet was closed. | |
/// | |
/// See also: | |
/// | |
/// * [BottomSheet], which is the widget normally returned by the function | |
/// passed as the `builder` argument to [showModalBottomSheet]. | |
/// * [showBottomSheet] and [ScaffoldState.showBottomSheet], for showing | |
/// non-modal bottom sheets. | |
/// * <https://material.google.com/components/bottom-sheets.html#bottom-sheets-modal-bottom-sheets> | |
Future<T> showModalBottomSheetApp<T>({ | |
@required BuildContext context, | |
@required WidgetBuilder builder, | |
bool dismissOnTap: false, | |
bool resizeToAvoidBottomPadding : true, | |
}) { | |
assert(context != null); | |
assert(builder != null); | |
return Navigator.push(context, new _ModalBottomSheetRoute<T>( | |
builder: builder, | |
theme: Theme.of(context, shadowThemeOnly: true), | |
barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, | |
resizeToAvoidBottomPadding: resizeToAvoidBottomPadding, | |
dismissOnTap: dismissOnTap, | |
)); | |
} |
motorahul
commented
Sep 20, 2019
via email
i get clone of your git project but there is error in contactlistpage.dart
…On Thu, Sep 19, 2019 at 8:57 PM rahul rawat ***@***.***> wrote:
thanks
On Thu, Sep 19, 2019 at 8:57 PM rahul rawat ***@***.***> wrote:
> i come to know that you create bloc.dart as a package
>
>
> On Thu, Sep 19, 2019 at 4:08 PM Aditya Gurjar ***@***.***>
> wrote:
>
>> can you please explain in case of authentication you
>> authenticatebloc.dart,authenticateevent.dart,authenticate.dart
>> intobloc.dart class thanks
>>
>> I think you're asking why I've created a Bloc.dart class for the
>> AuthenticationBloc?
>>
>> —
>> You are receiving this because you commented.
>> Reply to this email directly, view it on GitHub
>> <https://gist.github.com/79da87a8ac3678dca49b69a49709caf4?email_source=notifications&email_token=AKMFHNVQJPUPXGENTUYA2TTQKNJBHA5CNFSM4IYHOLN2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFZCKO#gistcomment-3032231>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AKMFHNWA5TVMLQA2EEUGQC3QKNJBHANCNFSM4IYHOLNQ>
>> .
>>
>
plz enable web support for it ,i trying to do it but didnot get any success
…On Fri, Sep 20, 2019 at 10:28 AM rahul rawat ***@***.***> wrote:
i get clone of your git project but there is error in
contactlistpage.dart
On Thu, Sep 19, 2019 at 8:57 PM rahul rawat ***@***.***> wrote:
> thanks
>
> On Thu, Sep 19, 2019 at 8:57 PM rahul rawat ***@***.***> wrote:
>
>> i come to know that you create bloc.dart as a package
>>
>>
>> On Thu, Sep 19, 2019 at 4:08 PM Aditya Gurjar ***@***.***>
>> wrote:
>>
>>> can you please explain in case of authentication you
>>> authenticatebloc.dart,authenticateevent.dart,authenticate.dart
>>> intobloc.dart class thanks
>>>
>>> I think you're asking why I've created a Bloc.dart class for the
>>> AuthenticationBloc?
>>>
>>> —
>>> You are receiving this because you commented.
>>> Reply to this email directly, view it on GitHub
>>> <https://gist.github.com/79da87a8ac3678dca49b69a49709caf4?email_source=notifications&email_token=AKMFHNVQJPUPXGENTUYA2TTQKNJBHA5CNFSM4IYHOLN2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFZCKO#gistcomment-3032231>,
>>> or mute the thread
>>> <https://github.com/notifications/unsubscribe-auth/AKMFHNWA5TVMLQA2EEUGQC3QKNJBHANCNFSM4IYHOLNQ>
>>> .
>>>
>>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment