Created
July 17, 2020 09:19
-
-
Save RobertBrunhage/29c569f41687e49b73830c07e1730d60 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
import 'package:flutter/material.dart'; | |
import 'package:hooks_riverpod/hooks_riverpod.dart'; | |
import 'package:flutter_hooks/flutter_hooks.dart'; | |
const kDialogSize = Size(550, 700); | |
final radiusProvider = Provider<double>((ref) { | |
return 8; | |
}); | |
class AdaptiveDialog extends HookWidget { | |
final Widget child; | |
const AdaptiveDialog({ | |
Key key, | |
@required this.child, | |
}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
final radius = useProvider(radiusProvider); | |
return LayoutBuilder( | |
builder: (context, dimens) { | |
if (dimens.maxWidth < kDialogSize.width || dimens.maxHeight < kDialogSize.height) { | |
return Scaffold( | |
appBar: AppBar( | |
elevation: 0, | |
leading: const CloseButton(), | |
), | |
body: ProviderScope( | |
overrides: [ | |
radiusProvider.overrideAs(Provider<double>((ref) => 0)), | |
], | |
child: child, | |
), | |
); | |
} | |
return Center( | |
child: Container( | |
width: kDialogSize.width, | |
height: kDialogSize.height, | |
decoration: BoxDecoration(borderRadius: BorderRadius.circular(radius)), | |
child: AspectRatio( | |
aspectRatio: 1, | |
child: Material( | |
child: child, | |
), | |
), | |
), | |
); | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment