Created
July 30, 2022 13:53
-
-
Save DaisukeNagata/865d0e2c2bca2b215b084bd710be695e to your computer and use it in GitHub Desktop.
Disabled if hidden, enabled vice versa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
), | |
), | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
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