2020-05-07 11:49:40 +00:00
|
|
|
import 'package:comunic/ui/widgets/icon_button_badge.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
/// Custom dropdown built for Appbar
|
|
|
|
///
|
|
|
|
/// @author Pierre Hubert
|
|
|
|
|
2020-05-07 11:50:57 +00:00
|
|
|
const _overlay_w = 300.0;
|
|
|
|
const _overlay_h = 400.0;
|
|
|
|
|
2020-05-07 11:49:40 +00:00
|
|
|
class AppBarCustomDropDownWidget extends StatefulWidget {
|
|
|
|
final Widget icon;
|
|
|
|
final int notificationsBadge;
|
|
|
|
final Widget Function(BuildContext) onBuildOverlay;
|
|
|
|
|
|
|
|
const AppBarCustomDropDownWidget({
|
2022-03-10 18:39:57 +00:00
|
|
|
Key? key,
|
|
|
|
required this.icon,
|
|
|
|
required this.notificationsBadge,
|
|
|
|
required this.onBuildOverlay,
|
2022-03-11 15:36:42 +00:00
|
|
|
}) : super(key: key);
|
2020-05-07 11:49:40 +00:00
|
|
|
|
|
|
|
@override
|
2020-05-07 16:12:11 +00:00
|
|
|
AppBarCustomDropDownWidgetState createState() =>
|
|
|
|
AppBarCustomDropDownWidgetState();
|
2020-05-07 11:49:40 +00:00
|
|
|
}
|
|
|
|
|
2020-05-07 16:12:11 +00:00
|
|
|
class AppBarCustomDropDownWidgetState
|
2020-05-07 11:49:40 +00:00
|
|
|
extends State<AppBarCustomDropDownWidget> {
|
2020-05-07 16:07:38 +00:00
|
|
|
bool _visible = false;
|
|
|
|
|
2020-05-07 11:49:40 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return IconButtonWithBadge(
|
|
|
|
icon: widget.icon,
|
|
|
|
onPressed: toggleOverlay,
|
|
|
|
number: widget.notificationsBadge,
|
2020-05-07 16:07:38 +00:00
|
|
|
active: _visible,
|
2020-05-07 11:49:40 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleOverlay() async {
|
2020-05-07 16:07:38 +00:00
|
|
|
setState(() => _visible = !_visible);
|
|
|
|
|
|
|
|
if (_visible) {
|
2022-03-10 18:39:57 +00:00
|
|
|
RenderBox renderBox = context.findRenderObject() as RenderBox;
|
2020-05-07 16:07:38 +00:00
|
|
|
final size = renderBox.size;
|
|
|
|
final offset = renderBox.localToGlobal(Offset(size.width, size.height));
|
|
|
|
|
|
|
|
Navigator.of(context).push(_AppBarCustomPopupRoute(
|
|
|
|
onBuild: widget.onBuildOverlay,
|
|
|
|
showContext: context,
|
|
|
|
offset: offset,
|
|
|
|
onDispose: () => setState(() => _visible = false),
|
|
|
|
));
|
|
|
|
} else
|
|
|
|
Navigator.of(context).pop();
|
2020-05-07 11:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AppBarCustomPopupRoute extends PopupRoute {
|
|
|
|
final BuildContext showContext;
|
|
|
|
final Widget Function(BuildContext) onBuild;
|
|
|
|
final Offset offset;
|
2020-05-07 16:07:38 +00:00
|
|
|
final void Function() onDispose;
|
2020-05-07 11:49:40 +00:00
|
|
|
|
|
|
|
_AppBarCustomPopupRoute({
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.showContext,
|
|
|
|
required this.onBuild,
|
|
|
|
required this.offset,
|
|
|
|
required this.onDispose,
|
2020-05-07 11:49:40 +00:00
|
|
|
});
|
|
|
|
|
2020-05-07 16:07:38 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
|
|
|
|
onDispose();
|
|
|
|
}
|
|
|
|
|
2020-05-07 11:49:40 +00:00
|
|
|
@override
|
2022-03-10 18:39:57 +00:00
|
|
|
Color? get barrierColor => null;
|
2020-05-07 11:49:40 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool get barrierDismissible => true;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String get barrierLabel =>
|
|
|
|
MaterialLocalizations.of(showContext).modalBarrierDismissLabel;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget buildPage(BuildContext context, Animation<double> animation,
|
|
|
|
Animation<double> secondaryAnimation) {
|
|
|
|
return MediaQuery.removePadding(
|
|
|
|
context: context,
|
|
|
|
removeTop: true,
|
|
|
|
removeBottom: true,
|
|
|
|
removeLeft: true,
|
|
|
|
removeRight: true,
|
|
|
|
child: Builder(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return _PopupContentBody(
|
|
|
|
onBuild: onBuild,
|
|
|
|
offset: offset,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Duration get transitionDuration => Duration(milliseconds: 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PopupContentBody extends StatelessWidget {
|
2022-03-10 18:39:57 +00:00
|
|
|
final Widget Function(BuildContext)? onBuild;
|
|
|
|
final Offset? offset;
|
2020-05-07 11:49:40 +00:00
|
|
|
|
2022-03-10 18:39:57 +00:00
|
|
|
const _PopupContentBody({Key? key, this.onBuild, this.offset})
|
2020-05-07 11:49:40 +00:00
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Stack(
|
|
|
|
children: <Widget>[
|
|
|
|
GestureDetector(
|
|
|
|
onTapDown: (d) => Navigator.of(context).pop(),
|
|
|
|
onPanDown: (d) => Navigator.of(context).pop(),
|
|
|
|
child: Container(color: Color(0x55000000)),
|
|
|
|
),
|
|
|
|
Positioned(
|
2022-03-10 18:39:57 +00:00
|
|
|
left: offset!.dx - _overlay_w + 4,
|
|
|
|
top: offset!.dy - 4,
|
2020-05-07 11:50:57 +00:00
|
|
|
width: _overlay_w,
|
|
|
|
height: _overlay_h,
|
2020-05-07 17:15:43 +00:00
|
|
|
child: Scaffold(
|
2022-03-10 18:39:57 +00:00
|
|
|
body: Card(child: onBuild!(context)),
|
2020-05-07 17:15:43 +00:00
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
),
|
2020-05-07 11:49:40 +00:00
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|