Created
January 19, 2021 10:32
-
-
Save Lootwig/8752606c08b16f2bb4ef62a1ce5998c8 to your computer and use it in GitHub Desktop.
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(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
builder: (_, widget) { | |
return Navigator( | |
onGenerateRoute: (_) => MaterialPageRoute(builder: (_) => widget), | |
); | |
}, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
visualDensity: VisualDensity.adaptivePlatformDensity, | |
), | |
routes: {'/': (_) => MyHomePage()}, | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
final _key = GlobalKey(); | |
@override | |
void initState() { | |
super.initState(); | |
WidgetsBinding.instance.addPostFrameCallback((_) { | |
final RenderBox _red = _key.currentContext.findRenderObject() as RenderBox; | |
final offset = _red.localToGlobal(Offset.zero); | |
Overlay.of(context).insert(OverlayEntry(builder: (_) { | |
return Positioned( | |
top: offset.dy, | |
child: Container( | |
color: Colors.blue, | |
width: 50, | |
height: 50, | |
), | |
); | |
})); | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: GestureDetector( | |
onTap: () => Navigator.of(context).pushNamed('/'), | |
child: Container( | |
key: _key, | |
color: Colors.red, | |
width: 50, | |
height: 50, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment