Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Created April 12, 2021 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepighetti/13080eb96875b46892e81fcc08d3f0cd to your computer and use it in GitHub Desktop.
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
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),
),
),
);
}
}
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