鸿蒙Next-TextInput制作简易登录页面

@Entry
@Component
struct EventCase {
  @State username: string = ''
  @State password: string = ''

  build() {
    Row() {
      Column({ space: 30 }) {
        TextInput({ placeholder: '请输入用户名', text: $$this.username })
          .height(40)

        TextInput({ placeholder: '请输入密码', text: $$this.password })
          .height(40)

          .type(InputType.Password)
        Button('登录')
          .width('100%')
          .onClick(() => {
            // console.log( this.username)
          })
      }
      .padding({
        left: 20,
        right: 20
      })
      .width('100%')
    }
    .height('100%')
  }
}

这里用到了TextInput的属性 实现密码框的设置

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TextInput是一个基础的widget,用于接收用户输入的文本。它没有UI外观,因此你需要自己构建UI来包装它。 以下是一个简单的示例,演示如何使用TextInput: ```dart import 'package:flutter/material.dart'; class MyTextInput extends StatefulWidget { @override _MyTextInputState createState() => _MyTextInputState(); } class _MyTextInputState extends State<MyTextInput> { final myController = TextEditingController(); @override void dispose() { myController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('My Text Input'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'Enter some text:', ), SizedBox(height: 10), Container( width: 300, child: TextField( controller: myController, decoration: InputDecoration( border: OutlineInputBorder(), hintText: 'Type something here', ), ), ), SizedBox(height: 10), RaisedButton( onPressed: () { showDialog( context: context, builder: (context) { return AlertDialog( title: Text('Your input'), content: Text(myController.text), actions: <Widget>[ FlatButton( child: Text('OK'), onPressed: () { Navigator.of(context).pop(); }, ), ], ); }, ); }, child: Text('Show input'), ), ], ), ), ); } } ``` 在这个示例中,我们创建了一个文本输入框,当用户输入文本时,它将被存储在TextEditingController中。当用户点击“Show input”按钮时,我们将会显示一个AlertDialog,其中包含用户输入的文本。 需要注意的是,在使用完TextInput后,我们需要调用TextEditingController的dispose()方法来释放资源。在StatefulWidget中,我们通常会在State的dispose()方法中调用它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值