- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 firebase_auth 在 flutter 中创建一个应用。
我有一个用于 View 的“登录”类和用于按钮和输入的其他“元素”类。我试图在 Elements 类的一个按钮上的 Login 类中设置一个函数,但我不知道如何从一个按钮设置一个函数到另一个。有人可以帮助我吗?
谢谢!
class Elements {
RaisedButton buttonPrimaryFilled(String _text) {
return new RaisedButton(
onPressed: (){
},
elevation: 4,
color: Colors.red,
child: new Container(
child: new Center(
child: new Text(_text,
textAlign: TextAlign.center,
style: new TextStyle(fontSize: 23,
color: Colors.white,
letterSpacing: 2,
fontWeight: FontWeight.bold
)
),
),
width: 350,
height: 50,
),
textColor: Colors.white,
);
}
}
class _LoginPageSate extends State<LoginPage> {
@override
Widget build(BuildContext context) {
//Button login
RaisedButton btnLogin = this.myElements.buttonPrimaryFilled("Iniciar sesión");
return new Scaffold(
body: new SingleChildScrollView(
child: new Center(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
//Here is the problem
btnLogin.onPressed,
]
),
),
),
),
}
}
最佳答案
首先,我强烈建议您为按钮使用扩展 (Stateless|Stateful)Widget 的特定类,而不是 Elements
类。
让我们为您的按钮创建一个 StatelessWidget,并允许向其传递参数
class PrimaryButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return // Your button here;
}
}
之后,您需要允许您的 PrimaryButton
类接收事件的回调
class PrimaryButton extends StatelessWidget {
PrimaryButton({this.onClick, this.child});
final String child;
final Function() onClick;
// ....
}
在您的构建方法中,您可以使用收到的这些属性
@override
Widget build(BuildContext context) {
return new RaisedButton(
onPressed: onClick,
elevation: 4,
color: Colors.red,
child: new Container(
width: 350,
height: 50,
child: new Center(
child: new Text(
text,
textAlign: TextAlign.center,
style: new TextStyle(
fontSize: 23,
color: Colors.white,
letterSpacing: 2,
fontWeight: FontWeight.bold
)
),
),
),
textColor: Colors.white,
);
}
要完成它,就在您需要的地方调用您的 PrimaryButton
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
PrimaryButton(
child: Text('Iniciar sesión'),
onClick: () { /* your function */ },
)
]
),
),
),
);
}
关于android - 如何在创建的 RaisedButton 对象中设置函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54515423/
我正在构建我的第一个应用程序来计算我工作所需的值。 我已经在 Python 中进行了这项工作,但这确实不同。 我有一个 textformfield,我在其中输入了“我需要的数据”。 成功后,我从“on
如何将图标添加到右侧的 RaisedButton Padding( padding: const EdgeInsets.only(top: 15.0), child:
我正在使用 firebase_auth 在 flutter 中创建一个应用。 我有一个用于 View 的“登录”类和用于按钮和输入的其他“元素”类。我试图在 Elements 类的一个按钮上的 Log
tl;dr 当我没有明确设置任何按钮时,为什么两个按钮之间会出现空格? 我正在尝试制作如下所示的布局: 但是,两个按钮之间出现了大约 16px 的空间,我不知道它是从哪里来的。 我起初以为 Colum
所以我试图移除 raisedButton 的底部边距,这样它看起来就好像与它下面的卡片合并了一样。这是它的样子 这是我的代码 Expanded( child: Card(
Flutter 按钮似乎都没有提供更改按钮矩形角半径的方法。有一个形状属性,但我不知道如何使用它。 最佳答案 您可以从 shape 属性更改半径,并给它一个 RoundedRectangleBorde
RaisedButton( onPressed: null, child: Text('Get in'), // change it to sign-in
我尝试从 themeData 更改我所有 RaisedButtons 的颜色,但它拒绝工作。所有其他属性,例如 fontSize 和 fontWeight 已成功更改。仅当 themeData 的亮度
我希望能够在将对象作为参数传递时按下按钮导航到另一个屏幕。该对象是使用不同 dart 文件中的 getPlayer() 函数创建的;因此,异步功能。每当我运行代码时,我都会收到错误: 错误:此表达式的
我读到的所有内容都表明您可以使用 SetState 完成这项工作。这是我一直在使用的,它不会重绘。 class ServerSelectionState extends State { bool
我很乐意从 RaisedButton 调用 Future fetchPost 或者换句话说,我不希望 FutureBuilder 在我点击按钮之前做任何事情,我尝试从按钮调用 fetchPost 但它
我的应用程序中有一个 TextField,紧接着是一个 RaisedButton。 当我输入 TextField 时,按钮会向上移动到键盘上方。如果我在 TextField 中一直向下滚动,我可以看到
我在一个列内有一个 RaisedButton,它在一个堆栈内 Stack( children: [ PageView( children: [...],
我正在尝试切换凸起按钮的颜色。最初按钮应该是蓝色的,当它被按下时它会变成灰色。现在我有一个名为 pressAttention 的 bool 值,它被设置为 false。我正在使用它来最初将其设置为 f
如何使 RaisedButton 成为选中状态,就像切换按钮选中状态一样? 如何使 RaisedButton 不占用额外的宽度,即虾皮包裹标签文本。 最佳答案 我相信我已经设法在不使用 RaisedB
对于上下文:https://dartpad.dev/c9689b40a5402e12538c726b5c0380ff 我有一个 GestureDetector(具有一些特定的业务逻辑),它监听单击并有
我有一个通用的按钮小部件,它将图标值作为构造函数。有时我希望小部件没有可见的图标。我如何将该逻辑放在看起来像这样的小部件中? const SocialAuthBtn({this.action, thi
我正在尝试使用 backgroundColor: '#fb933c' 使用内联样式自定义来更改 material-ui RaisedButton 的颜色,但它仍然显示默认颜色。 最佳答案 您可以使用内
我一直在尝试通过单击 RaisedButton 为 RadioListTile 提供背景颜色,并创建一个函数将该颜色分配给 RadioListTile包含特定的 value,例如 value: 2。我
我正在构建一个测验应用程序,它会在用户提交他们选择的答案后显示对正确答案的解释。 布局上有两个按钮——“下一个问题”和“提交答案”。 在初始状态下,“下一个问题”按钮很微妙,因为它不可点击,只有“提交
我是一名优秀的程序员,十分优秀!