0% found this document useful (0 votes)
126 views2 pages

Mobile Programming Practical-4

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.

Uploaded by

shubhampethani4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views2 pages

Mobile Programming Practical-4

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.

Uploaded by

shubhampethani4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Mobile Programming Practicals

Prac-4. Gestures in Dart programming


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'),
),
);
}
}

Output:

You might also like