import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:vrouter/vrouter.dart'; class MenuKalem { final String baslik; final IconData? simge; final String? rota; final VoidCallback? tiklandi; final List yetkiler; final List altMenuler; final GlobalKey key; MenuKalem({ required baslik, this.simge, this.rota, this.tiklandi, yetkiler, key, altMenuler, }) : baslik = baslik ?? "", yetkiler = yetkiler ?? [], altMenuler = altMenuler ?? [], key = key ?? GlobalKey(); } class WindowsYatayMenu extends StatelessWidget { WindowsYatayMenu({Key? key, menu}) : menu = menu ?? [ ], super(key: key); final List menu; @override Widget build(BuildContext context) { return Container( alignment: Alignment.centerLeft, height: 28, constraints: const BoxConstraints(maxWidth: 550), child: // ShaderMask( // shaderCallback: (Rect rect) { // return const LinearGradient( // begin: Alignment.centerLeft, // end: Alignment.centerRight, // colors: [ // Colors.white, // Colors.transparent, // Colors.transparent, // Colors.white // ], // stops: [ // 0.0, // 0.1, // 0.9, // 1.0 // ], // 10% purple, 80% transparent, 10% purple // ).createShader(rect); // }, // blendMode: BlendMode.dstOut, // child: ListView( shrinkWrap: true, physics: const BouncingScrollPhysics(), scrollDirection: Axis.horizontal, children: [ ...menu.map( (menuKalem) => Visibility( visible: true, child: IntrinsicWidth( child: Material( color: Colors.transparent, child: ListTile( key: menuKalem.key, leading: menuKalem.simge != null ? Icon( menuKalem.simge, size: 14, ) : null, contentPadding: EdgeInsets.zero, minLeadingWidth: 0, minVerticalPadding: 0, horizontalTitleGap: 0, visualDensity: VisualDensity(horizontal: 0, vertical: -4), title: Text( menuKalem.baslik, // softWrap: true, style: const TextStyle( fontWeight: FontWeight.w500, overflow: TextOverflow.ellipsis, ), ), dense: true, onTap: () async { if (menuKalem.tiklandi != null) { menuKalem.tiklandi!(); } if (menuKalem.altMenuler.isNotEmpty) { final RenderBox renderBox = menuKalem.key.currentContext!.findRenderObject() as RenderBox; //*get the global position, from the widget local position final offset = renderBox.localToGlobal(Offset.zero); //*calculate the start point in this case, below the button final left = offset.dx; final top = offset.dy + renderBox.size.height; //*The right does not indicates the width final right = left + renderBox.size.width; await showMenu( context: context, position: RelativeRect.fromLTRB(left, top, right, 0.0), // clipBehavior: Clip.hardEdge, items: List.generate(menuKalem.altMenuler.length, (index) { return PopupMenuItem( value: index, height: 0, padding: EdgeInsets.zero, child: ListTile( key: menuKalem.altMenuler[index].key, leading: menuKalem.altMenuler[index].simge != null ? Icon( menuKalem.altMenuler[index].simge, size: 16, ) : null, title: Center( child: Text( menuKalem.altMenuler[index].baslik, // softWrap: true, style: const TextStyle( fontWeight: FontWeight.w500, overflow: TextOverflow.ellipsis), ), ), dense: true, onTap: () { if (menuKalem.tiklandi != null) { menuKalem.tiklandi!(); } if (menuKalem.altMenuler[index].rota != null) { context.vRouter .to(menuKalem.altMenuler[index].rota!); } else {} }, ), ); }), elevation: 8.0, ).then((value) { if (value != null) { if (kDebugMode) { print(value); } } }); } else { if (menuKalem.rota != null) { context.vRouter.to(menuKalem.rota!); } } }, ), ), ), ), ), ], ), ); } }