Created
April 12, 2021 13:43
-
-
Save lukepighetti/13080eb96875b46892e81fcc08d3f0cd to your computer and use it in GitHub Desktop.
Using flutter_portal to create a popover that allows the base view to remain interactive
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(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
static const title = 'Spike Overlay TextField'; | |
@override | |
Widget build(BuildContext context) { | |
return Portal( | |
child: MaterialApp( | |
title: MyApp.title, | |
home: MyHomePage(), | |
), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
var _portalVisible = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(MyApp.title), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Padding( | |
padding: const EdgeInsets.all(20), | |
child: TextField(), | |
), | |
], | |
), | |
), | |
floatingActionButton: PortalEntry( | |
visible: _portalVisible, | |
portalAnchor: Alignment.bottomRight, | |
childAnchor: Alignment.topLeft, | |
portal: SizedBox( | |
height: 150, | |
width: 150, | |
child: Material( | |
child: Stack( | |
alignment: Alignment.topRight, | |
children: [ | |
/// Placeholder indicator | |
Placeholder( | |
color: Colors.grey.shade200, | |
), | |
/// Close button | |
IconButton( | |
icon: Icon(Icons.close), | |
onPressed: () { | |
setState(() { | |
_portalVisible = false; | |
}); | |
}, | |
), | |
], | |
), | |
), | |
), | |
child: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_portalVisible = true; | |
}); | |
}, | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), | |
), | |
); | |
} | |
} |
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
name: spike_overlay_text_field | |
description: A new Flutter project. | |
publish_to: "none" | |
version: 1.0.0+1 | |
environment: | |
sdk: ">=2.7.0 <3.0.0" | |
dependencies: | |
flutter: | |
sdk: flutter | |
cupertino_icons: ^1.0.2 | |
flutter_portal: ^0.3.0 | |
dev_dependencies: | |
flutter_test: | |
sdk: flutter | |
flutter: | |
uses-material-design: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment