Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Disabled if hidden, enabled vice versa
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
int _counter2 = 0;
bool _flg = false;
void _incrementCounter() {
setState(() {
_counter++;
});
}
void _incrementCounter2() {
setState(() {
_counter2++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Stack(
children: <Widget>[
AnimatedOpacity(
opacity: _flg ? 1 : 0,
duration: const Duration(milliseconds: 1),
child: IgnorePointer(
ignoring: _flg,
child: TextButton(
onPressed: () {
_incrementCounter();
_flg = true;
},
child: Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
),
),
),
AnimatedOpacity(
opacity: _flg ? 0 : 1,
duration: const Duration(milliseconds: 1),
child: IgnorePointer(
ignoring: !_flg,
child: TextButton(
onPressed: () {
_incrementCounter2();
_flg = false;
},
child: Text(
'${_counter2}2',
style: Theme.of(context).textTheme.headline4,
),
),
),
),
],
),
),
);
}
}
@daisukenagata
Copy link
Author

daisukenagata commented Jul 30, 2022

Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment