blob: 21b1ff98d5277d29eda05224102e74064c940ae4 [file] [log] [blame]
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
/// Flutter code sample for [GestureDetector].
void main() => runApp(const GestureDetectorExampleApp());
class GestureDetectorExampleApp extends StatelessWidget {
const GestureDetectorExampleApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: GestureDetectorExample(),
);
}
}
class GestureDetectorExample extends StatefulWidget {
const GestureDetectorExample({super.key});
@override
State<GestureDetectorExample> createState() => _GestureDetectorExampleState();
}
class _GestureDetectorExampleState extends State<GestureDetectorExample> {
bool _lightIsOn = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
alignment: FractionalOffset.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.lightbulb_outline,
color: _lightIsOn ? Colors.yellow.shade600 : Colors.black,
size: 60,
),
),
GestureDetector(
onTap: () {
setState(() {
// Toggle light when tapped.
_lightIsOn = !_lightIsOn;
});
},
child: Container(
color: Colors.yellow.shade600,
padding: const EdgeInsets.all(8),
// Change button text when light changes state.
child: Text(_lightIsOn ? 'TURN LIGHT OFF' : 'TURN LIGHT ON'),
),
),
],
),
),
);
}
}