Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Created July 30, 2022 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/865d0e2c2bca2b215b084bd710be695e to your computer and use it in GitHub Desktop.
Save DaisukeNagata/865d0e2c2bca2b215b084bd710be695e to your computer and use it in GitHub Desktop.
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

Example

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