- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在下面创建了一个自定义布局:
class CustomLayout extends StatelessWidget {
final Widget leading;
final String title;
final Widget body;
final List<Widget> bottomBar;
const CustomLayout({
Key key,Widget leading, String title, Widget body, this.bottomBar
}):leading = leading ?? const SizedBox(height: 0,),
title = title ?? "",
body = body ?? const SizedBox(),
super(key: key)
;
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Stack(
alignment: Alignment.topLeft,
children: [
/// Background
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("images/background.jpg"),
fit: BoxFit.cover
)
),
),
/// custom
Column(
children: [
/// SimpleAppbar
SizedBox(
height: (title == "")? 0 : 50,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.centerLeft,
children: [
Center(
child: Text(
title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24
),
),
),
Container(
padding: const EdgeInsets.only(left:4.0,top: 4.0),
child: leading,
),
],
),
),
/// body
Expanded(child: body),
/// bottomBar
SizedBox(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: bottomBar == null ? [SizedBox()]:bottomBar,
),
)
],
)
],
),
),
);
}
}
并使用这个布局:
CustomLayout(
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.white,
),
onPressed: (){
Navigator.of(context).pop();
},
),
body: // my code
);
无法按下前导参数,我搜索并得到了一些提示,这些提示可能是我的堆栈,但我已经检查了很多次。底栏和主体参数仍然可以正常工作。帮我!............................................... ..................................................... ..................................................... ..................................................... ..................................................... .....................
最佳答案
通常,堆栈用于分层格式,因此您在自定义布局中使用了扩展到正文的内容,这就是为什么它会占据整个屏幕的宽度和高度,并且它位于前导图标的顶部,这就是图标从不显示的原因被按下,所以我改变了你布局中的一些东西,看看吧。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SampleApp(),
debugShowCheckedModeBanner: false,
);
}
}
class SampleApp extends StatefulWidget {
@override
_SampleAppState createState() => _SampleAppState();
}
class _SampleAppState extends State<SampleApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Your app'),
),
body: Container(
child: CustomLayout(
leading: IconButton(
icon: Icon(
Icons.arrow_back,
color: Colors.black,
size: 20,
),
onPressed: () {
print('This is the tap');
},
),
body: Text('This is your body') // my code
),
));
}
}
class CustomLayout extends StatelessWidget {
final Widget leading;
final String title;
final Widget body;
final List<Widget> bottomBar;
const CustomLayout(
{Key key, Widget leading, String title, Widget body, this.bottomBar})
: leading = leading ??
const SizedBox(
height: 0,
),
title = title ?? "",
body = body ?? const SizedBox(),
super(key: key);
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Container(
child: Stack(
alignment: Alignment.topLeft,
children: [
/// Background
Container(
decoration: BoxDecoration(),
),
/// custom
Column(
children: [
/// SimpleAppbar
SizedBox(
height: (title == "") ? 0 : 50,
width: MediaQuery.of(context).size.width,
child: Stack(
alignment: Alignment.centerLeft,
children: [
Center(
child: Text(
title,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 24),
),
),
],
),
),
/// body
Expanded(child: body),
/// bottomBar
SizedBox(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: bottomBar == null ? [SizedBox()] : bottomBar,
),
),
],
),
Container(
padding: const EdgeInsets.only(left: 4.0, top: 5.0),
child: leading,
),
],
),
),
),
);
}
}
如果有用请告诉我
关于Flutter:IconButton 没有收到 onPressed 函数(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64998822/
我有以下 flatlist 渲染方法,在点击列表项时,它将调用 this._onPress 方法: render() { return (
我正在使用很棒的组件来自Native Base 。 import React, { Component } from 'react' import {View, Picker, Text, Butto
我正在做一个更大的项目,但不知道为什么这个小部分让我花了将近一整天的时间。 import 'package:flutter/material.dart'; void main() { runApp
我刚刚将我的 react-native 项目移植到 typescript 并且有一个关于函数作为 Prop 的问题 我通过: this.props.navigation.navigate("Card
我已经实现了教程中的 React Navigation 示例 https://reactnavigation.org/docs/intro/而且效果很好。 navigate('Chat')} t
我从RaisedButton创建了一个扩展类。传递onPressed参数时,该类拒绝说驱动器为空。 类 class VecRaisedButton extends RaisedButton { V
我正在制作简单的自定义文本按钮 SizedBox( height: 40, child: Material( color: Colors.transparent
onPressed 错误尝试传递 onPressed 函数但出现错误。 错误 - 无法将参数类型“Function”分配给参数类型“void Function()?”。 class CircleBut
onPressed 错误尝试传递 onPressed 函数但出现错误。 错误 - 无法将参数类型“Function”分配给参数类型“void Function()?”。 class CircleBut
RESET 我在上面看到的代码中使用了可触摸的不透明度。当我更改状态 working_pressure 但不按下按钮时,控制台会记录状态。问题是按下按钮时,根本没有记录任何内容。 我的最
我的应用程序中有这个聊天屏幕,我在旁边的 button 及其 onPress() 的帮助下发送消息, 代码如下: import React, { Component } from "react"; i
正在学习native React并学习更多关于javascript的知识,所以我仍然不明白关于它的行为的很多事情。我使用 TouchableOpacity 及其 onPress 属性创建了一个按钮组件
我正在尝试为我使用 Flutter 创建的游戏实现 onPressed 函数。如果我使用 RaisedButton 然后 onPressed 工作,但因为我想要一个图像然后我必须使用 Material
我需要在下面的图标上插入 onpressed() 函数(导航器推送到其他页面): Column buildButtonColumn(IconData icon, String label) {
我有这个容器: new Container( width: 500.0, padding: new EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 40
我正在尝试使用 onPressed 切换到 Flutter 项目中的不同屏幕,但它没有生成任何结果,不确定是什么原因。 这是主屏幕页面:
我的平面列表中有一些按钮,如下所示 const renderItem = ({ item }) => ; const Item = ({ name, slug }) => { return
我在 React Native 上处理 onPress 事件。第一次,我写了那个代码: =this.props.minimum) ? this.props.onDecrement
我如何实现这种效果?单击日期后,我想扩展我的 AppBar。 最佳答案 最简单的方法是设置一个变量,然后改变 bottom 的高度。小部件。 Scaffold( appBar: AppBa
我已经使用 Flutter 大约 8 周了。 太棒了,毫无疑问。 然而,自从我开始以来,一直有一些问题困扰着我,那就是为什么有些小部件有 onTap方法而其他人有 onPressed ?谷歌无法给我任
我是一名优秀的程序员,十分优秀!