overlay_container
1.0.0
一個顫抖的小部件,它將其孩子在原始小部件層次結構之外提供。

此演示以此為例。您還可以查看examples文件夾。
孩子傳遞給該小部件的小部件是在小部件層次結構之外渲染的,作為覆蓋式小部件樹的覆蓋層。結果,該小部件非常適合構建自定義下拉選項,自動完成建議,對話框等。將其視為絕對放置的小部件,並且在窗口小部件的其餘部分上具有正面的z索引。實際上,這是一位在撲朔迷離的覆蓋層和疊加層上的友好包裝紙。
如果您曾經使用過反應,那麼這會在某種程度上執行React Portal所做的事情。
import 'package:flutter/material.dart' ;
import 'package:overlay_container/overlay_container.dart' ;
class MyApp extends StatelessWidget {
@override
Widget build ( BuildContext context) {
return MaterialApp (
title : 'Overlay Container Demo' ,
theme : ThemeData (
primarySwatch : Colors .blue,
),
home : MyHomePage (),
);
}
}
class MyHomePage extends StatefulWidget {
_MyHomePageState createState () => _MyHomePageState ();
}
class _MyHomePageState extends State < MyHomePage > {
// Need to maintain a "show" state either locally or inside
// a bloc.
bool _dropdownShown = false ;
void _toggleDropdown () {
setState (() {
_dropdownShown = ! _dropdownShown;
});
}
@override
Widget build ( BuildContext context) {
return Scaffold (
appBar : AppBar (
title : Text ( 'Overlay Container Demo Page' ),
),
body : Padding (
padding : const EdgeInsets . all ( 20 ),
child : Column (
crossAxisAlignment : CrossAxisAlignment .start,
children : < Widget > [
RaisedButton (
onPressed : _toggleDropdown,
child : Column (
children : < Widget > [
Text ( "Dropdown button" ),
],
),
),
// By default the overlay (since this is a Column) will
// be added right below the raised button
// but outside the widget tree.
// We can change that by supplying a "position".
OverlayContainer (
show : _dropdownShown,
// Let's position this overlay to the right of the button.
position : OverlayContainerPosition (
// Left position.
150 ,
// Bottom position.
45 ,
),
// The content inside the overlay.
child : Container (
height : 70 ,
padding : const EdgeInsets . all ( 20 ),
margin : const EdgeInsets . only (top : 5 ),
decoration : BoxDecoration (
color : Colors .white,
boxShadow : < BoxShadow > [
BoxShadow (
color : Colors .grey[ 300 ],
blurRadius : 3 ,
spreadRadius : 6 ,
)
],
),
child : Text ( "I render outside the n widget hierarchy." ),
),
),
],
),
),
);
}
}這裡可以找到一個更詳盡的例子。