Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Sign-in-with-Google button in Flutter in accordance with the terms

I'd like to add a "Sign in with Google" Button to my Flutter app. This button should be in accordance with the terms of Google.

My problem is, that the button I've create looks really awful.

I used the images which Google provides on their website but I don't know if I'm doing right with the code for the button.

  Widget _createLoginButtonGoogle() {
    return new Expanded(
      child: new Container(
        margin: EdgeInsets.fromLTRB(30.0, 5.0, 30.0, 5.0),
        child: new RaisedButton(
          color: const Color(0xFF4285F4),
          shape: _createButtonBorder(),
          onPressed: () {},
          child: new Row(
            children: <Widget>[
              new Image.asset(
                'res/images/icons/google/btn_google_dark_normal_mdpi.9.png',
                height: 48.0,
              ),
              new Expanded(
                child: _createButtonText('Sign in with Google', Colors.white),
              ),
            ],
          ),
        ),
      ),
    );
  }

What I want is that my button looks like the original Google button

original google button

And not like my version

my version of the google button

Can anyone tell me how to create the original google button? Is there a better way than creating a RaisedButton?

like image 709
Mani76 Avatar asked Oct 25 '18 10:10

Mani76


Video Answer


3 Answers

you can use Padding property of raised button also use property of Row widget and mainAxisSize of button. Following code may help you to understand clearly.

 new Container(
      margin: EdgeInsets.fromLTRB(30.0, 5.0, 30.0, 5.0),
      child: new RaisedButton(
        padding: EdgeInsets.only(top: 3.0,bottom: 3.0,left: 3.0),
        color: const Color(0xFF4285F4),
        onPressed: () {},
        child: new Row(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            new Image.asset(
              'res/images/icons/google/btn_google_dark_normal_mdpi.9.png',
              height: 48.0,
            ),
            new Container(
              padding: EdgeInsets.only(left: 10.0,right: 10.0),
                child: new Text("Sign in with Google",style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),)
            ),
          ],
        )
      ),
    ),
like image 130
Viren V Varasadiya Avatar answered Oct 11 '22 13:10

Viren V Varasadiya


I'm giving you a general idea, replace Android icon with your Google image using Image.asset(google_image)

InkWell(
  onTap: () {},
  child: Ink(
    color: Color(0xFF397AF3),
    child: Padding(
      padding: EdgeInsets.all(6),
      child: Wrap(
        crossAxisAlignment: WrapCrossAlignment.center,
        children: [
          Icon(Icons.android), // <-- Use 'Image.asset(...)' here
          SizedBox(width: 12),
          Text('Sign in with Google'),
        ],
      ),
    ),
  ),
)

enter image description here

like image 24
CopsOnRoad Avatar answered Oct 11 '22 13:10

CopsOnRoad


There Is A Pretty Awesome Package Called flutter_signin_button on pub.dev.

You Can Use It It Has Sign In Buttons For

  • Email
  • Google
  • Facebook
  • GitHub
  • LinkedIn
  • Pinterest
  • Tumblr
  • Twitter
  • Apple

With Some Supporting Dark Mode Also With Mini Buttons!

First Add It To Your pubspec.yaml

dependencies:
  ...
  flutter_signin_button:

then import it into your file:

import 'package:flutter_signin_button/flutter_signin_button.dart';

and use the buttons like this:

SignInButton(
  Buttons.Google,
  onPressed: () {},
)

Here Is A Preview Of All The Buttons: enter image description here

like image 3
Adison Masih Avatar answered Oct 11 '22 13:10

Adison Masih