Want to remove or manage space in Flutter ListView Builder? You facing this issue due to auto padding in ListTile. you can use Inkwell and Row to achieve same effect.
Following Code May help you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', theme: new ThemeData( primarySwatch: Colors.blue, ), home: new Scaffold( appBar: new AppBar( title: new Text("check"), ), drawer: XmobeMenu(5), ), ); } } final List<MenuItem> menuItems = <MenuItem>[ MenuItem(0,'Home',Icons.home,Icons.chevron_right), MenuItem(0,'Home',Icons.home,Icons.chevron_right), MenuItem(0,'Home',Icons.home,Icons.chevron_right), MenuItem(0,'Home',Icons.home,Icons.chevron_right), MenuItem(0,'Home',Icons.home,Icons.chevron_right), MenuItem(0,'Home',Icons.home,Icons.chevron_right), MenuItem(0,'Home',Icons.home,Icons.chevron_right), ]; class XmobeMenu extends StatelessWidget { int indexNumber; XmobeMenu(int menuIndex) { indexNumber =menuIndex; } @override Widget build(BuildContext context) { return Drawer( child: ListView.builder( itemBuilder: (BuildContext context, int index) { return MenuItemWidget(menuItems[index],indexNumber); }, itemCount: menuItems.length, ), ); } } class MenuItem { MenuItem(this.itemNumber,this.title, this.leadIcon, this.trailIcon,); final int itemNumber; final IconData leadIcon; final IconData trailIcon; final String title; } class MenuItemWidget extends StatelessWidget { final MenuItem item; final int indexNumber; const MenuItemWidget(this.item, this.indexNumber); Widget _buildMenu(MenuItem menuItem, context) { return InkWell( onTap: () { Navigator.of(context).push( new MaterialPageRoute( builder: (BuildContext context) => MyApp(), ), ); }, child: new Container( color: const Color.fromARGB(0, 245,245,245), child: new Column( children: <Widget>[ new Column( children: <Widget>[ Container( padding: new EdgeInsets.all(8.0), // what ever padding you want add here child: Row( children: <Widget>[ new Icon(menuItem.leadIcon), new Expanded ( child: new Text(menuItem.title), ), new Icon(menuItem.trailIcon), ], ) ), Divider(height: 1.0,color: Colors.grey,), ],) ], ), ), ); } bool _checkEnabled(int itemNumber, int index) { if(itemNumber==index) { return true; } else { return false; } } @override Widget build(BuildContext context) { return _buildMenu(this.item, context); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.