This document discusses using gestures in Dart programming to display a button and message when pressed. It provides code for a Flutter app that contains a GestureDetector wrapping a button. When the button is tapped, it will show a snackbar message saying "You just tapped the button". The code creates a Scaffold with AppBar and centers the button widget.
This document discusses using gestures in Dart programming to display a button and message when pressed. It provides code for a Flutter app that contains a GestureDetector wrapping a button. When the button is tapped, it will show a snackbar message saying "You just tapped the button". The code creates a Scaffold with AppBar and centers the button widget.
1) To display a button and message after pressing it using gestures in dart. Code: import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key);
@override Widget build(BuildContext context) { const title = 'Gestures Demo';
return const MaterialApp(
title: title, home: MyHomePage(title: title), ); } } class MyHomePage extends StatelessWidget { final String title; const MyHomePage({Key? key, required this.title}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Flutter Practical(A-09)'), backgroundColor: Colors.green, ), body: const Center(child: MyButton()), ); } } class MyButton extends StatelessWidget { const MyButton({Key? key}) : super(key: key); @override Widget build(BuildContext context) { // The GestureDetector wraps the button. return GestureDetector( // show snackbar on tap of child onTap: () { const snackBar = SnackBar(content: Text(" You just Tapped on the Button")); ScaffoldMessenger.of(context).showSnackBar(snackBar); }, // The tap button child: Container( padding: const EdgeInsets.all(20.0), decoration: BoxDecoration( // ignore: deprecated_member_use color: Colors.blue, borderRadius: BorderRadius.circular(10.0), ), child: const Text('Tap Button'), ), ); } }