我对Flutter 翼和dart 是新手.我想删除覆盖图.我在网上试了很多答案,但还是卡住了.请看我的代码
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _insertOverlay(BuildContext context) {
return Overlay.of(context).insert(
OverlayEntry(builder: (context) {
return Positioned(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
top: 0,
left: 0,
child: Material(
color: const Color(0xFF0E3311).withOpacity(0.5),
child: GestureDetector(
onTap: (){
print('OVERLAY ON');
//on tap, remove or hide the overlay
},
child: Container( decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.redAccent), ),
),
),
);
}),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'Flutter application',
),
Text(
'',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: ()=>WidgetsBinding.instance.addPostFrameCallback((_) => _insertOverlay(context)),
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
我已经能够使覆盖显示出来,但我正在try 删除或隐藏它.看看我到目前为止做了什么.我做这件事已经有一段时间了.提前谢谢你