flutter 中的 OTP 页面

问题描述 投票:0回答:2

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

flutter user-interface flutter-layout flutter-dependencies
2个回答
1
投票

在 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
  ]),


0
投票

对于 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");
              },)
© www.soinside.com 2019 - 2024. All rights reserved.