Skip to content

Instantly share code, notes, and snippets.

@Lootwig
Created January 19, 2021 10:32
Show Gist options
  • Save Lootwig/8752606c08b16f2bb4ef62a1ce5998c8 to your computer and use it in GitHub Desktop.
Save Lootwig/8752606c08b16f2bb4ef62a1ce5998c8 to your computer and use it in GitHub Desktop.
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