Last active
September 3, 2023 17:22
-
-
Save Lootwig/71e32b14656ff7eb8b3c6538230e77cd to your computer and use it in GitHub Desktop.
flutter portal bug
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'; | |
import 'package:flutter_portal/flutter_portal.dart'; | |
void main() { | |
runApp(const App()); | |
} | |
class App extends StatefulWidget { | |
const App({super.key}); | |
@override | |
State<App> createState() => _AppState(); | |
} | |
class _AppState extends State<App> { | |
@override | |
Widget build(BuildContext context) { | |
return Portal( | |
child: MaterialApp( | |
home: PortalTarget( | |
visible: true, | |
portalFollower: const Align( | |
alignment: Alignment.bottomCenter, | |
child: A(), | |
), | |
child: Builder( | |
builder: (context) { | |
return Scaffold( | |
body: Center( | |
child: ElevatedButton( | |
onPressed: () { | |
Navigator.of(context).push(MaterialPageRoute( | |
builder: (context) => | |
Scaffold(body: Center(child: Text('2'))), | |
)); | |
}, | |
child: Text('push'), | |
), | |
), | |
); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} | |
class A extends StatefulWidget { | |
const A({super.key}); | |
@override | |
State<A> createState() => _AState(); | |
} | |
class _AState extends State<A> { | |
bool _toggle = false; | |
@override | |
Widget build(BuildContext context) { | |
return GestureDetector( | |
onTap: () => setState(() { | |
_toggle = !_toggle; | |
Future.delayed(const Duration(seconds: 1), () { | |
setState(() => _toggle = false); | |
}); | |
}), | |
child: Container( | |
width: 200, | |
height: 200, | |
color: Colors.black, | |
alignment: Alignment.center, | |
child: AnimatedOpacity( | |
duration: const Duration(seconds: 1), | |
opacity: _toggle ? 1 : 0, | |
child: const Text('A'), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment