Basic For Click Event Gesturedetector Or Inkwell In Flutter

admin_img Posted By Bajarangi soft , Posted On 09-10-2020

Basics For Adding Click Event For A Widget In Flutter

Basic For Click Event Gesturedetector Or Inkwell In Flutter

Basics For Adding Click Event

Complete Code For Basics For Adding Click Event In Flutter
Main.dart

import 'package:flutter/material.dart';
void main() {
  runApp(
      MaterialApp(
        debugShowCheckedModeBanner: false,
        home: MyApp(),
      )
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String name = "no name";
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        backgroundColor: Colors.amber,
        title: new Text("My App Title"),
      ),
      backgroundColor: Colors.white70,
      body:  Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(name),
              ],
            ),

            Row(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                IconButton(
                  icon: Icon(Icons.star),
                  onPressed: () {
                    setState(() {
                      name = "Bajarangisoft.com";
                    });
                  },
                ),

                GestureDetector(
                  child: new Text("Gesture"),
                  onTap: () {
                    setState(() {
                      name = "Welcome TO Bajarangisoft";
                    });
                  },
                ),

                InkWell(
                  child: Container(
                    child: Text("InkWell"),
                  ),
                  onTap: changeName,
                )
              ],
            ),

          ],
        ),
      ),
    );
  }

  void changeName() {
    setState(() {
      name = "Your own codes";
    });
  }
}

Related Post