2

I am working on sidebar in flutter, I need to add a submenu to the alreay existing menu Items.

I have two files, menu_items.dart and sidebar.dart. Menu_Items codes:

import 'package:flutter/material.dart';

class MenuItem extends StatelessWidget {
  const MenuItem({Key key, this.icon, this.title, this.onTap})
      : super(key: key);
  final IconData icon;
  final String title;
  final Function onTap;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Row(
          children: [
            Icon(
              icon,
              color: Colors.white,
              size: 20,
            ),
            SizedBox(
              width: 20,
            ),
            Text(
              title,
              style: TextStyle(
                fontWeight: FontWeight.w300,
                fontSize: 15,
                color: Colors.white,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

This is how I am using it in Sidebar.dart:

   MenuItem(
      icon: Icons.sensor_window,
      title: 'Sensor Parameters',
      ),

The thing is, I need to make the sensor parameter

enter image description here

a parent dropdown, with a list of menu items that I already have. The sub-menu dropdown Items are:

TemChartClickEvent,
 HumChartClickEvent,
 MoisChartClickEvent,
 PhChartClickEvent,
 NurChartClickEvent,
 GasChartClickEvent,

Which are created using bloc patterns. The parent menu:

MenuItem(
      icon: Icons.sensor_window,
      title: 'Sensor Parameters',
      ),

I have been sourcing the internet to get a good resource and make up the menu, but, I couldn't get it to work.

Anyone can help me set it up, giving that I already have MenuItem code above, how do I fit in another bunch of codes call DropDownMenu with its functions, and then pass it into the parent menu, "MenuItem" code above

isofttechn
  • 400
  • 1
  • 6
  • 19

1 Answers1

2

You have pass ExpansionTile Widget Or Used multilevel_drawer package

Drawer(
  child: ListView(
  children: <Widget>[
  ExpansionTile(
  title: Text("Expansion Title"),
    children: <Widget>[Text("children 1"), Text("children 2")],
  )
 ],
 ),
);
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
  • Now that I have my MenuItem class, how do I fit in the MLMenuItem with subMenuItems without conflicting with mine? – isofttechn Jul 07 '21 at 09:56
  • Try `MenuItem( icon: Icons.sensor_window, title: 'Sensor Parameters', ),` replace by text widget inside children of expansiontile – Ravindra S. Patil Jul 07 '21 at 10:01
  • I am getting this error: RenderBox was not laid out: RenderSemanticsAnnotations#25c5c relayoutBoundary=up13 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1940 pos 12: 'hasSize' – isofttechn Jul 07 '21 at 15:12
  • Try to add your MenuItem inside Expanded or Flexible Widget like as `Expanded(child:MenuItem(icon: Icons.sensor_window,title: 'Sensor Parameters',),),` – Ravindra S. Patil Jul 08 '21 at 03:53