otp_plus 1.0.9 copy "otp_plus: ^1.0.9" to clipboard
otp_plus: ^1.0.9 copied to clipboard

powerful, customizable package for handling PIN code. otp_plus makes it easy to implement elegant and responsive code input UIs.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:otp_plus/otp_plus.dart';
import 'package:otp_plus/utils/enum/otp_field_shape.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final GlobalKey<OtpPlusInputsState> otpKey = GlobalKey<OtpPlusInputsState>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Test OTP Plus'),
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: ListView(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        children: [
          const SizedBox(height: 70),
          Text(
            'Input your code here:',
            style: TextStyle(
              fontSize: 20,
              color: Colors.black,
              fontWeight: FontWeight.w400,
            ),
          ),
          const SizedBox(height: 30),
          Center(
            child: OtpPlusInputs(
              key: otpKey,
              size: 50,
              length: 6,
              shape: OtpFieldShape.square,
              textDirection: TextDirection.ltr,
              onChanged: (code) {
                debugPrint('On Changed : $code');
              },
              onSubmit: (code) {
                debugPrint('On Submit : $code');
              },
              //Add optional values here
              onComplete: (code) {
                // Add OTP verification logic here
                debugPrint('OTP completed: $code');
              },
            ),
          ),
          const SizedBox(height: 24),
          Center(
            child: ElevatedButton(
              onPressed: () {
                /// Call clearControllerData() via the key to clear input fields value
                otpKey.currentState?.clearControllerData();
                setState(() {});
              },
              child: const Text('Clear OTP'),
            ),
          ),
        ],
      ),
    );
  }
}
4
likes
160
points
400
downloads

Publisher

unverified uploader

Weekly Downloads

powerful, customizable package for handling PIN code. otp_plus makes it easy to implement elegant and responsive code input UIs.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on otp_plus