【发布时间】:2020-10-02 12:52:10
【问题描述】:
我想通过单击 AppBar 的 IconButton 来隐藏我的 Image 容器。但是我的 AppBar 的 IconButton 不起作用。 我想,我的代码出错了.....
import 'package:flutter/material.dart';
import 'package:icon_shadow/icon_shadow.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
bool viewVisible = true;
/* void showWidget() {
setState(() {
viewVisible = true;
});
print("Pressed");
}
*/
void hideWidget() {
setState(() {
viewVisible = false;
print("Work");
});
}
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text("Icon & Image Shadow Demo"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.arrow_drop_down_circle),
onPressed: hideWidget,
)
],
),
body: Stack(
children: <Widget>[
ListView(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconShadowWidget(
Icon(
Icons.add_circle,
color: Colors.red,
size: 100.0,
),
),
IconShadowWidget(
Icon(
Icons.add_circle,
color: Colors.red,
size: 100.0,
),
shadowColor: Colors.black,
),
IconShadowWidget(
Icon(
Icons.add_circle,
color: Colors.red,
size: 100.0,
),
shadowColor: Colors.black,
showShadow: false,
),
],
),
SizedBox(
height: 5.0,
),
Visibility(
maintainAnimation: true,
maintainSize: true,
maintainState: true,
visible: viewVisible,
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.8),
spreadRadius: 5,
blurRadius: 3,
offset:
Offset(5, 7), // changes position of shadow
),
],
),
child: Image.asset("assets/images/download.png"),
),
)
],
),
],
)
],
)),
);
}
}
【问题讨论】:
标签: flutter visibility