- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试在我的 AppBar
小部件上单击 IconButton
后构建折叠 View ,我使用了 ExpansionTile
但在我之后没有任何反应单击 IconButton
。
appBar: AppBar(
actions: <Widget>[
IconButton(
onPressed: () {
ExpansionTile(
title: Text(
"Settings",
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold
),
),
);
},
icon: Icon(Icons.settings),
),
],
),
我的代码写对了吗,还是应该考虑重构它。提前致谢!
最佳答案
是的,您需要重构代码,因为您不能通过这种方式直接从函数中将小部件插入到小部件树中。我不确定您要做什么,所以我做了两个假设(1)您正在尝试在应用栏中显示扩展磁贴或(2)您想要显示弹出菜单。请查看下面我的代码以了解如何实现这两者。
import 'package:flutter/material.dart';
final Color darkBlue = const Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
title: 'Welcome to Flutter',
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
Widget myWidget = Container(
child: const Text("Flutter"),
);
String myText = 'Hello, World!';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: myWidget, actions: [
IconButton(
onPressed: () async {
print(context);
showMenu(
context: context,
position: const RelativeRect.fromLTRB(110.0, 80.0, 0.0, 0.0),
items: ["One", "Two", "Three", "Four"]
.map(
(value) => PopupMenuItem<String>(
child: Text(value),
value: value,
),
)
.toList(),
elevation: 8.0,
);
},
icon: Icon(Icons.settings),
),
PopupMenuButton<int>(
onSelected: (selected) {
setState(
() {
myText = "You selected the menu number $selected";
},
);
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<int>>[
const PopupMenuItem<int>(
value: 1,
child: Text('First Item'),
),
const PopupMenuItem<int>(
value: 2,
child: Text('Second Item'),
),
const PopupMenuItem<int>(
value: 3,
child: Text('Thrid Item'),
),
const PopupMenuItem<int>(
value: 4,
child: Text('Fourth Item'),
),
],
)
]),
body: Center(
child: Text(myText, style: Theme.of(context).textTheme.headline4),
),
);
}
}
关于flutter - AppBar flutter 中 IconButton 内的 ExpansionTile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64860497/
这是我的代码,我创建了一个 ExpansionTile 并且它有一个子 TextFormField。 import 'package:flutter/material.dart'; class Ord
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我的问题是: Flutter 有没有办法只允许扩展动态生成的 ListView 的一个 ExpansionTile? 例如我的 ListView 有三个 ExpansionTiles,我点击第一个,它
如何删除 ExpansionTile 中前导 Widget 中的垂直填充,使其看起来像下面的 ListTile? 这是我的代码: Container( decoration: BoxDecorat
有没有办法让 Flutter ExpansionTile 小部件上的旋转展开箭头作为前导而不是尾随? 最佳答案 const ExpansionTile( title: Text('
以下问题:我有一个列表 ExpansionTiles效果很好。我面临的唯一问题是,滚动到 View 之外的展开的 ExpansionTile 在再次滚动到 View 后将不再展开。这会导致不良的用户体
我创建了一个 expandtile,并将原来的尾随图标更改为我自定义的 svg 图标。每当我单击扩展图 block 时...一切正常,但新的 svg 尾随图标不会像原始尾随图标那样旋转。请问我该如何解
我正在打开一个表单来输入详细信息,并在填写完所有内容并提交后将其关闭,但只有尾随图标发生了变化,我还试图在 onExpansionChanged 中设置更改。但不会反射(reflect)在 UI 中。
我正在尝试使用扩展图 block 并在少数情况下禁用扩展功能...可以这样做吗?我的意思是任何现有的“扩展”小部件是否涵盖了这个东西?如果没有,那么是否有任何可用的软件包可以帮助我做到这一点?我应该如
我需要更改尾随的颜色 keyboard_down_arrow在 ExpansionTile .我曾尝试将它包装在 Theme 小部件中并设置重音、primary 和 IconTheme,但似乎没有任何
我有一个 ExpansionTile与 TextField当用户展开磁贴时,尝试将焦点设置到此文本字段。但由于某些原因,我无法让它工作。 这是代码: ExpansionTile( key: Pag
默认情况下,我们在 ExpansionTile 的 header 中有 16 个水平填充,因为它是 ListTile 并且它有 /// If null, `EdgeInsets.symmetric(h
listview 在 ExpansionTile 中不工作 我试图在 ExpansionTile 中显示一个 listview.builder,但它抛出了一些异常 Card( child
我将此作为扩展和折叠扩展瓦片的引用------ Flutter - Collapsing ExpansionTile after choosing an item 我想要的是,如果我打开一个扩展图 b
是否可以在 flutter 中更改扩展图 block ?具体来说,我想删除它在扩展时创建的分隔符。我也想调整它的填充。那可能吗?谢谢! 最佳答案 来自ExpansionTile的来源 https://
我试图让 ExpansionTile 在我选择一个项目后折叠,但它不会关闭打开的列表。 我尝试使用 onExpansionChanged 属性但没有成功 你怎么能解决这个问题? 插入一个gif,演示E
我想在“ExpansionTile”打开时更改颜色。当我打开我的 ExpansionTile 时,此时我得到了白色背景,但打开后我想要浅灰色,看起来像我的第一个屏幕截图这是我的代码。 我也想增加我的图
我想要做的是将圆角边缘应用到整个瓷砖,即使是在 child 内部的容器打开时,就像它折叠时一样。 我尝试使用 BoxDecoration 通过其容器应用样式,但它给了我错误。我不知道如何继续,因为与
我建了一个 Listview与 ExpansionTile .但是现在我想要,如果我点击 ExpansionTile那么只有ExpansionTile应开等 展开ExpansionTile应该关闭。
我想降低 expansionTile 的高度, 我试过了ConfigurableExpansionTile但它不支持空安全,所以我不能在我的项目中使用它。 我还在 ListTileTheme 中包装了
我是一名优秀的程序员,十分优秀!