Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to Change background color of UserAccountsDrawerHeader in Drawer. #26164

Closed
saltpetre opened this issue Jan 7, 2019 · 7 comments
Closed
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list

Comments

@saltpetre
Copy link

saltpetre commented Jan 7, 2019

Steps to Reproduce

Goal: Have a transparent drawer including the UserAccountDrawerHeader.

Unable to change color of UserAccountsDrawerHeader in Drawer to transparent.

Able to change DrawerHeader color to transparent using container. But that workaround does not work for UserAccountsDrawerHeader.

Below code for UserAccountDrawerHeader. (Using red to represent as transparent is not visible.)

    SystemChrome.restoreSystemUIOverlays();
    return Scaffold(
      
      appBar: AppBar(
       
        //Make visible status bar txt and icon in ios. 
        brightness: Brightness.light,
        elevation: 0.0,
        backgroundColor: Colors.transparent, //APP BAR TRANSPARENT
        
        iconTheme: new IconThemeData(color: Colors.black),//DRAWER ICON COLOR
        ),
        
       drawer: Theme(
         data: Theme.of(context).copyWith(

           canvasColor: Colors.transparent,
           
         ),
        child: Drawer(
      
          child:(
          ListView(
          
          
          padding: EdgeInsets.zero,
          
          children: <Widget>[
            new Container(
              color: Colors.transparent,
            child: UserAccountsDrawerHeader(
              currentAccountPicture: CircleAvatar(),

            ),
            ),

            ListTile(
              title: Text('Item 1'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        )
          ),
        ),
       ),

**Below code using DrawerHeader and able to get transparent background using container
But unable to get the same effect, arrangement and ease of UserAccountDrawerHeader
**

       drawer: Theme(
         data: Theme.of(context).copyWith(

           canvasColor: Colors.transparent,
           
         ),
        child: Drawer(
      
          child:(
          ListView(
          
          padding: EdgeInsets.zero,
          
          children: <Widget>[

            new Container(
              color: Colors.transparent,
           child: DrawerHeader(
              padding: EdgeInsets.all(50),
              child: Text('THIS IS DRAWER HEADER'),

           ),
            ),
            ListTile(
              title: Text('Item 1'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
            ListTile(
              title: Text('Item 2'),
              onTap: () {
                // Update the state of the app
                // ...
                // Then close the drawer
                Navigator.pop(context);
              },
            ),
          ],
        )
          ),
        ),
       ),

flutter doctor -v

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.13.6 17G65, locale en)
    • Flutter version 1.0.0 at /Users/saltpetre/flutter/flutter
    • Framework revision 5391447fae (5 weeks ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/saltpetre/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling
      support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.4.1, Build version 9F2000
    • ios-deploy 1.9.4
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 31.3.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build
      1.8.0_152-release-1136-b06)

[✓] VS Code (version 1.30.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 2.21.1

[✓] Connected device (2 available)
    • Android SDK built for x86 • emulator-5554                        •
      android-x86 • Android 5.1.1 (API 22) (emulator)
    • iPhone X                  • 5C3481A6-E784-44D6-AEFB-B68BF6A6AC57 • ios
      • iOS 11.4 (simulator)

• No issues found!
@zoechi
Copy link
Contributor

zoechi commented Jan 7, 2019

Can you please post complete runnable code so that copy/paste is enough to run?

Please consider asking support questions in one of the other channels listed at http://flutter.io/support .

@zoechi zoechi added the framework flutter/packages/flutter repository. See also f: labels. label Jan 7, 2019
@zoechi zoechi added this to the Goals milestone Jan 7, 2019
@zoechi zoechi added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 7, 2019
@goderbauer goderbauer added the f: material design flutter/packages/flutter/material repository. label Jan 7, 2019
@saltpetre
Copy link
Author

saltpetre commented Jan 8, 2019

Hi Gunter,

I think i found a workaround for the issue but don't know if its good. ALSO now there is very very thin divider line below the UserAccout box and primarycolorbrightness does not get override using copywith. Please see complete working code main.dart. I have put in comments for your reference. Thanks

### MAIN.DART

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        canvasColor: Colors.white,
        primaryColor: Colors
            .red, //**this is to check is overide works in drawer theme. */
        primaryColorBrightness:
            Brightness.dark, /** unable to overide in drawer theme */
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.restoreSystemUIOverlays();
    return Scaffold(
      appBar: AppBar(
        //Makes visible status bar txt and icon in ios.
        brightness: Brightness.light,
        elevation: 0.0,
        backgroundColor: Colors.transparent, //APP BAR TRANSPARENT
        iconTheme: new IconThemeData(color: Colors.black), //DRAWER ICON COLOR
      ),

      drawer: Theme(
        data: Theme.of(context).copyWith(
          canvasColor: Colors.transparent,
          primaryColor: Colors.transparent, //***PRIMARY COLOR overide works */

          //** */DOES NOT OVERRIDE THEMEDATA IN MATERIALAPP***
          primaryColorBrightness: Brightness.light,
        ),
        child: Drawer(
          child: (ListView(
            padding: EdgeInsets.zero,
            children: <Widget>[
              new Container(
                padding: EdgeInsets.only(top: 100),
                color: Colors.transparent,
                child: UserAccountsDrawerHeader(
                  currentAccountPicture: CircleAvatar(
                      backgroundColor: Color.fromRGBO(255, 244, 200, 0.1)),
                  accountName: Text('NAME'),
                  accountEmail: Text('XYZ@gmail.com'),
                ),
              ),
              ListTile(
                title: Text('Item 1'),
                onTap: () {
                  Navigator.pop(context);
                },
              ),
              ListTile(
                title: Text('Item 2'),
                onTap: () {
                  // Update the state of the app
                  // ...
                  // Then close the drawer
                  Navigator.pop(context);
                },
              ),
            ],
          )),
        ),
      ),

      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 8, 2019
@zoechi
Copy link
Contributor

zoechi commented Jan 8, 2019

very very thin divider line

This sounds like #14288

@cbracken
Copy link
Member

/cc @HansMuller who may have thoughts.

Agreed with @zoechi re: the divider line.

@kf6gpe kf6gpe added the P2 Important issues not at the top of the work list label May 29, 2020
@darshankawar
Copy link
Member

Hi @saltpetreca, can you please confirm if you still experience this issue with latest Flutter version (eg: dev, master)?
UserAccountDrawerHeader has decoration property through which you can provide transparent color. Sample working code below:

child: UserAccountsDrawerHeader(
      decoration: BoxDecoration(
        color: Colors.transparent
      ),

Using above snippet and the code sample you provided, I was able to see the UserAccountHeaderDrawer background to be transparent.

26164

If you confirm that this is no longer an issue and works as intended, you may close this ticket.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jul 10, 2020
@darshankawar
Copy link
Member

Without additional information we are unfortunately not sure how to resolve this issue.
We are therefore reluctantly going to close this bug for now.
Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away!
Thanks for your contribution.

Could everyone who still has this problem please file a new issue with the exact description of what happens, logs and the output of flutter doctor -v.
All system setups can be slightly different, so it's always better to open new issues and reference related issues.

@pedromassangocode pedromassangocode removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 20, 2021
@github-actions
Copy link

github-actions bot commented Aug 6, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. P2 Important issues not at the top of the work list
Projects
None yet
Development

No branches or pull requests

8 participants
@cbracken @zoechi @goderbauer @kf6gpe @saltpetre @darshankawar @pedromassangocode and others