Change Drawer Selected Menu Item Background Color In Flutter

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

In this android programming source code example, we are going to change the color of navigation drawer indicator icon in android. You can copy and adopt this. In this android programming source code example, we are going to change the color of navigation drawer indicator icon in android. You can copy and adopt this source code example to your android project without reinventing the wheel. Below is a step by step source code to change the color of navigation drawer indicator icon in android.

Change Drawer Selected Menu Item Background Color In Flutter

Change Drawer Selected Menu Item Background Color
Complete Code For Change Drawer Selected Menu Item Background Color In Flutter
main.dart

import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}
class MyHomePage extends StatefulWidget {
  static final List<String> _listViewData = [
    "Flutter",
    "Ios",
    "Dart",
    "Android",
    "Laravel",
    "Php",
    "Html",
  ];

  @override
  State<StatefulWidget> createState() => MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> {
  int _currentSelected = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.deepPurple,
        title: Text("Change Drawer Selected Item"),
      ),
      drawer: Container(
        width: 250,
        child: Drawer(
          child: Container(
            child: ListView.builder(
              padding: EdgeInsets.all(10.0),
              itemCount: MyHomePage._listViewData.length,
              itemBuilder: (context, index) {
                return Container(
                  color: _currentSelected == index ? Colors.deepPurple : Colors.white,
                  child: ListTile(
                    title: Text(MyHomePage._listViewData[index]),
                    onTap: () {
                      setState(() {
                        _currentSelected = index;
                      });
                    },
                  ),
                );
              },
            ),
          ),
        ),
      ),
      body: Center(
        child: Text('Main Body'),
      ),
    );
  }
}

Related Post