Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Create Elevated Button with Icon and Text in Flutter

Tags:

flutter

dart

How to create a button that has text and an icon by using the latest button widget ElevatedButton.

like image 406
Javeed Ishaq Avatar asked Sep 13 '25 10:09

Javeed Ishaq


2 Answers

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Elevated Button',
      home: FlutterExample(),
    );
  }
}

class FlutterExample extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text('Elevated Button with Icon and Text')),
        body: Center(
            child: ElevatedButton.icon(
          icon: Icon(
            Icons.home,
            color: Colors.green,
            size: 30.0,
          ),
          label: Text('Elevated Button'),
          onPressed: () {
            print('Button Pressed');
          },
          style: ElevatedButton.styleFrom(
            shape: new RoundedRectangleBorder(
              borderRadius: new BorderRadius.circular(20.0),
            ),
          ),
        )));
  }
}
like image 155
S4nj33v Avatar answered Sep 16 '25 00:09

S4nj33v


You can use ElevatedButton.icon constructor:

ElevatedButton.icon(
                  onPressed: () {
                      //OnPressed Logic
                  },
                  icon: const Icon(Icons.plus_one),
                  label: const Text(
                      "Button Text"
                  )
                ),
like image 31
tomerpacific Avatar answered Sep 16 '25 01:09

tomerpacific