flutter 中的 OTP 页面

发布于 2025-01-11 18:58:02 字数 197 浏览 0 评论 0原文

我怎样才能在flutter中制作这样的otp页面,请帮助我并分享特定照片的完整代码,谢谢

< img src="https://i.sstatic.net/SVAIR.jpg" alt="在此处输入图像描述">

How can i make otp page like this in flutter, kindly help me and share whole code for the specific photo thanks

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心空情空意 2025-01-18 18:58:02

在 pubspec.yaml 中添加以下包

otp_text_field:
  git:
    url: https://github.com/AkashMore7427/OTPTextField

在 dart 文件中添加以下导入行

import 'package:otp_text_field/otp_field.dart';
import 'package:otp_text_field/otp_field_style.dart';
import 'package:otp_text_field/style.dart';

将以下代码添加到正文

Column(children: [
    // Image.network("Add Image Link"),
    Text(
      "Enter verification Code",
    ),
    Text(
      "Code sent to [email protected]",
    ),
    OTPTextField(
        length: 4,
        width: MediaQuery.of(context).size.width,
        fieldWidth: 50,
        style: TextStyle(fontSize: 17),
        textFieldAlignment: MainAxisAlignment.spaceAround,
        onCompleted: (pin) {
          print("Completed: " + pin);
        },
        otpFieldStyle: OtpFieldStyle(
          borderColor: Colors.black,
        )),

    Text("Resend in 0:45"),
    //Add Button Widget Here
  ]),

< img src="https://i.sstatic.net/2GaO4m.png" alt="在此处输入图像描述">

Add Following Package in pubspec.yaml

otp_text_field:
  git:
    url: https://github.com/AkashMore7427/OTPTextField

Add the following import line in your dart file

import 'package:otp_text_field/otp_field.dart';
import 'package:otp_text_field/otp_field_style.dart';
import 'package:otp_text_field/style.dart';

Add the following code to your body

Column(children: [
    // Image.network("Add Image Link"),
    Text(
      "Enter verification Code",
    ),
    Text(
      "Code sent to [email protected]",
    ),
    OTPTextField(
        length: 4,
        width: MediaQuery.of(context).size.width,
        fieldWidth: 50,
        style: TextStyle(fontSize: 17),
        textFieldAlignment: MainAxisAlignment.spaceAround,
        onCompleted: (pin) {
          print("Completed: " + pin);
        },
        otpFieldStyle: OtpFieldStyle(
          borderColor: Colors.black,
        )),

    Text("Resend in 0:45"),
    //Add Button Widget Here
  ]),

enter image description here

帅气称霸 2025-01-18 18:58:02

或者,对于 otp 字段,您可以使用 FlutterOtpField 包,它提供 inputDecoration 属性。使用 inputDecoration,您可以将自己的设计设置为 OTP 文本字段。

例子:

FlutterOtpField(
              inputFieldLength: 4,
              spaceBetweenFields: 10,
              inputDecoration: InputDecoration(
                  constraints: const BoxConstraints(maxHeight: 46),
                  fillColor: Colors.transparent,
                  filled: true,
                  hintText: "#",
                  counterText: "",
                  hintStyle: const TextStyle(
                      color: Color(0xff656565),
                      fontSize: 14,
                      fontWeight: FontWeight.w500),
                  enabledBorder: OutlineInputBorder(
                      borderSide: const BorderSide(
                          color: Color(0xff969696),
                          width: 1.0),
                      borderRadius:
                      BorderRadius.circular(30)),
                  focusedBorder: OutlineInputBorder(
                      borderSide: const BorderSide(
                          color: Color(0xff969696),
                          width: 1.0),
                      borderRadius:
                      BorderRadius.circular(30))),
              onValueChange: (String value) {
                print("otp changed $value");
              },
              onCompleted: (String value) {
                print("otp  $value");
              },)

Alternatively for otp fields you can use FlutterOtpField package where it provides inputDecoration property. With inputDecoration you can set your own design to OTP textFields.

Example:

FlutterOtpField(
              inputFieldLength: 4,
              spaceBetweenFields: 10,
              inputDecoration: InputDecoration(
                  constraints: const BoxConstraints(maxHeight: 46),
                  fillColor: Colors.transparent,
                  filled: true,
                  hintText: "#",
                  counterText: "",
                  hintStyle: const TextStyle(
                      color: Color(0xff656565),
                      fontSize: 14,
                      fontWeight: FontWeight.w500),
                  enabledBorder: OutlineInputBorder(
                      borderSide: const BorderSide(
                          color: Color(0xff969696),
                          width: 1.0),
                      borderRadius:
                      BorderRadius.circular(30)),
                  focusedBorder: OutlineInputBorder(
                      borderSide: const BorderSide(
                          color: Color(0xff969696),
                          width: 1.0),
                      borderRadius:
                      BorderRadius.circular(30))),
              onValueChange: (String value) {
                print("otp changed $value");
              },
              onCompleted: (String value) {
                print("otp  $value");
              },)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文