Skip to content

Instantly share code, notes, and snippets.

@Craftplacer
Created May 9, 2023 20:11
Show Gist options
  • Save Craftplacer/06e80fa5aa4553a544e6f1e93118550a to your computer and use it in GitHub Desktop.
Save Craftplacer/06e80fa5aa4553a544e6f1e93118550a to your computer and use it in GitHub Desktop.
import "package:flutter/material.dart";
class ResponsiveMenu extends StatelessWidget {
final Function(BuildContext context, VoidCallback onTap)? builder;
final List<Widget> Function(
BuildContext context,
VoidCallback? onClose,
) itemBuilder;
const AdaptiveMenu({
super.key,
required this.itemBuilder,
this.builder,
});
@override
Widget build(BuildContext context) {
return MenuAnchor(
builder: builder == null
? null
: (builder) => (context, controller, _) {
return builder(
context,
() => _onTap(context, controller),
);
},
menuChildren: itemBuilder(context, null),
child: const Icon(Icons.more_vert_rounded),
);
}
Future<void> _onTap(BuildContext context, MenuController controller) async {
if (MediaQuery.of(context).size.width >= 600) {
controller.open();
return;
}
await showModalBottomSheet(
context: context,
builder: (context) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(height: 26),
...itemBuilder(
context,
() => Navigator.of(context).maybePop(),
),
],
);
},
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment