Skip to content

Instantly share code, notes, and snippets.

@Lootwig
Last active September 3, 2023 17:22
Show Gist options
  • Save Lootwig/71e32b14656ff7eb8b3c6538230e77cd to your computer and use it in GitHub Desktop.
Save Lootwig/71e32b14656ff7eb8b3c6538230e77cd to your computer and use it in GitHub Desktop.
flutter portal bug
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