Get Button Name On Button Click Using Flutter Android App

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

The sample Google flutter code below illustrate how to get button name on button click in flutter.

Get Button Name On Button Click Using Flutter Android App

Get Button Name On Button Click
Complete Code For Get Button Name On Button Click In Flutter
main.dart

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

void main(){
  runApp(MyApp());
}

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _buttonName = "";

  _onPressed() {
    setState(() {
      _buttonName = "A Button Name";
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.amber,
          title: Text('Button Name'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Text("Button Name: $_buttonName"),
              RaisedButton(
                onPressed: _onPressed,
                child: Text('A Button Name'),
                color: Colors.amber,
              )
            ],
          ),
        ));
  }
}

Related Post