Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to add a logo image on the left side of AppBar?

Tags:

flutter

dart

I want to add a logo image on the left side of my AppBar, as following: https://i.stack.imgur.com/qGIbb.png

This is my current code:

main.dart:

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(title: "Chat App", home: new LoginPage());
  }
}

home_page.dart:

import 'package:flutter/material.dart';

class LoginPage extends StatelessWidget {
  @override 
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Smart ID',
      home: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage("assets/background.png"), fit: BoxFit.cover)),
        child: Scaffold(
          backgroundColor: Colors.transparent,
          appBar: AppBar(
            elevation: 0,
            backgroundColor: Color(0xff05B068),
            centerTitle: true,
            title: Text('SMARTID', style: TextStyle(fontFamily: 'Open Sans', fontWeight: FontWeight.bold)),
          ),
        ),
      )
    );
  }
}

How do I apply the logo image?

like image 539
Nadia M Avatar asked Dec 14 '22 10:12

Nadia M


2 Answers

Do it like,

      appBar: AppBar(
        leading: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Image.asset(
            "assets/images/appicon.png",
          ),
        ),


Output

enter image description here

Add your logo in assets folder like this,

enter image description here

Then open pubspec.yaml and add your logo,

enter image description here

At last, press get packages,

enter image description here

like image 78
Ravinder Kumar Avatar answered May 24 '23 17:05

Ravinder Kumar


There is a parameter called leading that takes a widget and places it on the left side of your AppBar.

Replace the Icon that i put with your logo:

AppBar(
          elevation: 0,
          backgroundColor: Color(0xff05B068),
          centerTitle: true,
          leading: Icon(Icons.arrow_forward_ios),
          title: Text('SMARTID', style: TextStyle(fontFamily: 'Open Sans', fontWeight: FontWeight.bold)),
        ),
like image 44
Mohamad Assem Nasser Avatar answered May 24 '23 19:05

Mohamad Assem Nasser