### Configure Installation Paths and Components Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt Sets up installation directories and components for the application's runtime files. This ensures that the application and its dependencies are installed correctly. ```cmake # === Installation === # Support files are copied into place next to the executable, so that it can # run in place. This is done instead of making a separate bundle (as on Linux) # so that building and running from within Visual Studio will work. set(BUILD_BUNDLE_DIR "$") # Make the "install" step default, as it's required to run. set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/CMakeLists.txt Installs the Flutter assets directory to the application bundle. Ensures the directory is clean before installation. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Installation Rules for Application Bundle Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/CMakeLists.txt Configures the installation process to create a relocatable application bundle. It cleans the build directory, sets installation destinations for the executable, ICU data, Flutter library, bundled libraries, and native assets. ```cmake # === Installation === # By default, "installing" just makes a relocatable bundle in the build # directory. set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() # Start with a clean build bundle directory every time. install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) # Copy the native assets provided by the build.dart from all packages. set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) # Fully re-copy the assets directory on each build to avoid having stale files ``` -------------------------------- ### Install Application Runtime Files Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt Installs the main executable, Flutter ICU data, Flutter library, and any bundled plugin libraries. This makes the application ready for deployment. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Basic Pinput Widget Example Source: https://context7.com/tkko/flutter_pinput/llms.txt Demonstrates the basic usage of the Pinput widget with a length of 6 and callbacks for completion and changes. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class BasicPinputExample extends StatelessWidget { const BasicPinputExample({super.key}); @override Widget build(BuildContext context) { return Pinput( length: 6, onCompleted: (pin) { print('Completed: $pin'); }, onChanged: (value) { print('Changed: $value'); }, ); } } ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt Installs the Flutter assets directory. It ensures that the assets directory is completely re-copied on each build to prevent stale files. ```cmake # Fully re-copy the assets directory on each build to avoid having stale files # from a previous install. set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install AOT Library (Non-Debug) Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/CMakeLists.txt Installs the Ahead-of-Time (AOT) compiled library on non-Debug builds only. This is crucial for performance in release environments. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Find and check PkgConfig modules for GTK Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/flutter/CMakeLists.txt This section uses PkgConfig to find and check for required GTK modules (gtk+-3.0, glib-2.0, gio-2.0). Ensure these packages are installed on your system. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Themed Pinput Widget Example Source: https://context7.com/tkko/flutter_pinput/llms.txt Shows how to customize the appearance of Pinput fields using PinTheme for default, focused, submitted, and error states. Requires Flutter and Pinput packages. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class ThemedPinputExample extends StatelessWidget { const ThemedPinputExample({super.key}); @override Widget build(BuildContext context) { final defaultPinTheme = PinTheme( width: 56, height: 56, textStyle: const TextStyle( fontSize: 20, color: Color.fromRGBO(30, 60, 87, 1), fontWeight: FontWeight.w600, ), decoration: BoxDecoration( border: Border.all(color: const Color.fromRGBO(234, 239, 243, 1)), borderRadius: BorderRadius.circular(20), ), ); final focusedPinTheme = defaultPinTheme.copyDecorationWith( border: Border.all(color: const Color.fromRGBO(114, 178, 238, 1)), borderRadius: BorderRadius.circular(8), ); final submittedPinTheme = defaultPinTheme.copyWith( decoration: defaultPinTheme.decoration?.copyWith( color: const Color.fromRGBO(234, 239, 243, 1), ), ); final errorPinTheme = defaultPinTheme.copyDecorationWith( border: Border.all(color: Colors.red), ); return Pinput( length: 4, defaultPinTheme: defaultPinTheme, focusedPinTheme: focusedPinTheme, submittedPinTheme: submittedPinTheme, errorPinTheme: errorPinTheme, showCursor: true, onCompleted: (pin) => print(pin), ); } } ``` -------------------------------- ### SMS Autofill Before Pinput 5.0.0 Source: https://github.com/tkko/flutter_pinput/blob/master/MIGRATION.md This example shows how to configure SMS autofill using `androidSmsAutofillMethod` and `listenForMultipleSmsOnAndroid` before version 5.0.0. ```dart class Example extends StatelessWidget { const Example({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Pinput( androidSmsAutofillMethod: AndroidSmsAutofillMethod.smsUserConsentApi, listenForMultipleSmsOnAndroid: true, ); } } ``` -------------------------------- ### Install AOT Library Conditionally Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library for Profile and Release configurations. This is typically not included in Debug builds. ```cmake # Install the AOT library on non-Debug builds only. install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Rounded With Shadow Theme Example Source: https://context7.com/tkko/flutter_pinput/llms.txt Demonstrates creating a modern pin input with rounded corners, shadows, and custom cursor styling. Requires importing 'package:flutter/material.dart' and 'package:pinput/pinput.dart'. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class RoundedWithShadowExample extends StatefulWidget { const RoundedWithShadowExample({super.key}); @override State createState() => _RoundedWithShadowExampleState(); } class _RoundedWithShadowExampleState extends State { final controller = TextEditingController(); final focusNode = FocusNode(); @override void dispose() { controller.dispose(); focusNode.dispose(); super.dispose(); } @override Widget build(BuildContext context) { final defaultPinTheme = PinTheme( width: 60, height: 64, textStyle: const TextStyle( fontSize: 20, color: Color.fromRGBO(70, 69, 66, 1), ), decoration: BoxDecoration( color: const Color.fromRGBO(232, 235, 241, 0.37), borderRadius: BorderRadius.circular(24), ), ); final cursor = Align( alignment: Alignment.bottomCenter, child: Container( width: 21, height: 1, margin: const EdgeInsets.only(bottom: 12), decoration: BoxDecoration( color: const Color.fromRGBO(137, 146, 160, 1), borderRadius: BorderRadius.circular(8), ), ), ); return Pinput( length: 4, controller: controller, focusNode: focusNode, defaultPinTheme: defaultPinTheme, separatorBuilder: (index) => const SizedBox(width: 16), focusedPinTheme: defaultPinTheme.copyWith( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8), boxShadow: const [ BoxShadow( color: Color.fromRGBO(0, 0, 0, 0.06), offset: Offset(0, 3), blurRadius: 16, ), ], ), ), showCursor: true, cursor: cursor, onCompleted: (pin) => print('Completed: $pin'), ); } } ``` -------------------------------- ### SMS Autofill Implementation After Pinput 5.0.0 Source: https://github.com/tkko/flutter_pinput/blob/master/MIGRATION.md This example demonstrates the implementation of SMS autofill using the `smart_auth` package and the `SmsRetrieverImpl` class after Pinput version 5.0.0. It requires initializing `SmartAuth` and passing an instance of `SmsRetrieverImpl` to the `Pinput` widget. ```dart class SmsRetrieverImpl implements SmsRetriever { const SmsRetrieverImpl(this.smartAuth); final SmartAuth smartAuth; @override Future dispose() { return smartAuth.removeSmsListener(); } @override Future getSmsCode() async { final res = await smartAuth.getSmsCode(); if (res.succeed && res.codeFound) { return res.code!; } return null; } @override bool get listenForMultipleSms => false; } class SmartAuthExample extends StatefulWidget { const SmartAuthExample({Key? key}) : super(key: key); @override State createState() => _SmartAuthExampleState(); } class _SmartAuthExampleState extends State { late final SmsRetrieverImpl smsRetrieverImpl; @override void initState() { smsRetrieverImpl = SmsRetrieverImpl(SmartAuth()); super.initState(); } @override Widget build(BuildContext context) { return Pinput( smsRetriever: smsRetrieverImpl, ); } } ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt Specifies the minimum required CMake version and defines the project name. This is a standard starting point for any CMake project. ```cmake cmake_minimum_required(VERSION 3.14) project(example LANGUAGES CXX) ``` -------------------------------- ### Integrate Custom Pin Themes and Validation Source: https://github.com/tkko/flutter_pinput/blob/master/README.md Combine custom pin themes with validation logic and Pinput controller settings. This example shows how to apply default, focused, and submitted themes, along with validation and autovalidation modes. ```dart final defaultPinTheme = PinTheme( width: 56, height: 56, textStyle: TextStyle(fontSize: 20, color: Color.fromRGBO(30, 60, 87, 1), fontWeight: FontWeight.w600), decoration: BoxDecoration( border: Border.all(color: Color.fromRGBO(234, 239, 243, 1)), borderRadius: BorderRadius.circular(20), ), ); final focusedPinTheme = defaultPinTheme.copyDecorationWith( border: Border.all(color: Color.fromRGBO(114, 178, 238, 1)), borderRadius: BorderRadius.circular(8), ); final submittedPinTheme = defaultPinTheme.copyWith( decoration: defaultPinTheme.decoration.copyWith( color: Color.fromRGBO(234, 239, 243, 1), ), ); return Pinput( defaultPinTheme: defaultPinTheme, focusedPinTheme: focusedPinTheme, submittedPinTheme: submittedPinTheme, validator: (s) { return s == '2222' ? null : 'Pin is incorrect'; }, pinputAutovalidateMode: PinputAutovalidateMode.onSubmit, showCursor: true, onCompleted: (pin) => print(pin), ); ``` -------------------------------- ### Configure Flutter library and headers Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/flutter/CMakeLists.txt Sets the paths for the Flutter library and ICU data file, and defines the list of Flutter library headers. These are published to the parent scope for use in the install step. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) ``` ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Project-level CMake Configuration Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/CMakeLists.txt Sets the minimum CMake version, project name, executable name, and application ID. It also enables modern CMake behaviors and sets the installation path for bundled libraries. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) # The name of the executable created for the application. Change this to change # the on-disk name of your application. set(BINARY_NAME "example") # The unique GTK application identifier for this application. See: # https://wiki.gnome.org/HowDoI/ChooseApplicationID set(APPLICATION_ID "ge.fman.example") # Explicitly opt in to modern CMake behaviors to avoid warnings with recent # versions of CMake. cmake_policy(SET CMP0063 NEW) # Load bundled libraries from the lib/ directory relative to the binary. set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Root filesystem for cross-building. if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() # Define build configuration options. if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Set CMake Minimum Version Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Specifies the minimum version of CMake required for this configuration. Ensure your CMake installation meets this requirement. ```cmake cmake_minimum_required(VERSION 3.14) ``` -------------------------------- ### Flutter Pinput Custom Cursor Example Source: https://context7.com/tkko/flutter_pinput/llms.txt Displays a custom cursor widget for the focused pin field, with optional cursor animation. Use this to provide visual feedback for the active input field. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class CustomCursorExample extends StatelessWidget { const CustomCursorExample({super.key}); @override Widget build(BuildContext context) { final defaultPinTheme = PinTheme( width: 56, height: 56, textStyle: const TextStyle(fontSize: 22, color: Color.fromRGBO(30, 60, 87, 1)), decoration: const BoxDecoration(), ); // Custom bottom line cursor final cursor = Column( mainAxisAlignment: MainAxisAlignment.end, children: [ Container( width: 56, height: 3, decoration: BoxDecoration( color: const Color.fromRGBO(30, 60, 87, 1), borderRadius: BorderRadius.circular(8), ), ), ], ); // Pre-filled widget shown for empty fields final preFilledWidget = Column( mainAxisAlignment: MainAxisAlignment.end, children: [ Container( width: 56, height: 3, decoration: BoxDecoration( color: Colors.grey.shade300, borderRadius: BorderRadius.circular(8), ), ), ], ); return Pinput( length: 5, defaultPinTheme: defaultPinTheme, showCursor: true, cursor: cursor, preFilledWidget: preFilledWidget, isCursorAnimationEnabled: true, pinAnimationType: PinAnimationType.slide, onCompleted: (pin) => print('Completed: $pin'), ); } } ``` -------------------------------- ### Tap Outside Handling Example Source: https://context7.com/tkko/flutter_pinput/llms.txt Handles taps outside the pin input to unfocus the widget and dismiss the keyboard. Requires importing 'package:flutter/material.dart' and 'package:pinput/pinput.dart'. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class TapOutsideExample extends StatefulWidget { const TapOutsideExample({super.key}); @override State createState() => _TapOutsideExampleState(); } class _TapOutsideExampleState extends State { final focusNode = FocusNode(); Offset? tapPosition; @override void dispose() { focusNode.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Pinput( length: 4, focusNode: focusNode, // Called when tap down outside the pinput onTapOutside: (event) { tapPosition = event.position; }, // Called when tap up outside - use to distinguish tap from scroll onTapUpOutside: (event) { // Only unfocus if tap position matches (not scrolling) if (event.position == tapPosition) { focusNode.unfocus(); } tapPosition = null; }, onCompleted: (pin) => print('Completed: $pin'), ); } } ``` -------------------------------- ### Custom Keyboard Integration with Pinput Source: https://context7.com/tkko/flutter_pinput/llms.txt Disable the native keyboard and control pin input programmatically for custom keyboard implementations. This example shows how to use Pinput with a custom numeric keypad. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class CustomKeyboardExample extends StatefulWidget { const CustomKeyboardExample({super.key}); @override State createState() => _CustomKeyboardExampleState(); } class _CustomKeyboardExampleState extends State { final pinController = TextEditingController(); @override void dispose() { pinController.dispose(); super.dispose(); } void _onKeyPressed(String key) { if (key == 'delete') { pinController.delete(); } else { pinController.append(key, 4); } } @override Widget build(BuildContext context) { return Column( children: [ Pinput( length: 4, controller: pinController, useNativeKeyboard: false, // Disable native keyboard showCursor: true, onCompleted: (pin) => print('Completed: $pin'), ), const SizedBox(height: 40), // Custom numeric keyboard GridView.count( shrinkWrap: true, crossAxisCount: 3, childAspectRatio: 1.5, children: [ ...List.generate(9, (i) => _buildKey('${i + 1}')), const SizedBox(), _buildKey('0'), _buildKey('delete', icon: Icons.backspace_outlined), ], ), ], ); } Widget _buildKey(String value, {IconData? icon}) { return InkWell( onTap: () => _onKeyPressed(value), child: Container( margin: const EdgeInsets.all(4), decoration: BoxDecoration( color: Colors.grey.shade200, borderRadius: BorderRadius.circular(8), ), child: Center( child: icon != null ? Icon(icon, size: 24) : Text(value, style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), ), ), ); } } ``` -------------------------------- ### Pinput Controller and FocusNode Management Source: https://context7.com/tkko/flutter_pinput/llms.txt Manages Pinput's state programmatically using TextEditingController and FocusNode, with examples of setting text, appending digits, deleting, focusing, and unfocusing. Ensure to dispose of controllers and focus nodes. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class ControllerExample extends StatefulWidget { const ControllerExample({super.key}); @override State createState() => _ControllerExampleState(); } class _ControllerExampleState extends State { final pinController = TextEditingController(); final focusNode = FocusNode(); @override void dispose() { pinController.dispose(); focusNode.dispose(); super.dispose(); } void _setPin() { // Set text programmatically using extension method pinController.setText('1234'); } void _appendDigit(String digit) { // Append character with max length constraint pinController.append(digit, 4); } void _deleteLastDigit() { // Delete last character using extension method pinController.delete(); } void _focusPinput() { focusNode.requestFocus(); } void _unfocusPinput() { focusNode.unfocus(); } @override Widget build(BuildContext context) { return Column( children: [ Pinput( length: 4, controller: pinController, focusNode: focusNode, onCompleted: (pin) => print('Completed: $pin'), ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ElevatedButton(onPressed: _setPin, child: const Text('Set 1234')), ElevatedButton(onPressed: _deleteLastDigit, child: const Text('Delete')), ElevatedButton(onPressed: _focusPinput, child: const Text('Focus')), ], ), ], ); } } ``` -------------------------------- ### Pinput Form Validation Example Source: https://context7.com/tkko/flutter_pinput/llms.txt Integrates Pinput with Flutter's Form for validation. Supports onSubmit auto-validation and manual validation triggers. Includes custom error text styling. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class ValidationExample extends StatefulWidget { const ValidationExample({super.key}); @override State createState() => _ValidationExampleState(); } class _ValidationExampleState extends State { final formKey = GlobalKey(); final pinController = TextEditingController(); @override void dispose() { pinController.dispose(); super.dispose(); } void _validatePin() { formKey.currentState!.validate(); } @override Widget build(BuildContext context) { return Form( key: formKey, child: Column( children: [ Pinput( length: 4, controller: pinController, // Auto validate after completion or submission pinputAutovalidateMode: PinputAutovalidateMode.onSubmit, validator: (pin) { if (pin == '2222') return null; return 'Pin is incorrect'; }, // Custom error text style errorTextStyle: const TextStyle( color: Colors.red, fontSize: 12, ), onCompleted: (pin) => print('Completed: $pin'), ), const SizedBox(height: 20), // Force error state manually Pinput( length: 4, forceErrorState: true, errorText: 'This pin is always in error state', showErrorWhenFocused: true, ), const SizedBox(height: 20), ElevatedButton( onPressed: _validatePin, child: const Text('Validate'), ), ], ), ); } } ``` -------------------------------- ### Customizing Pin Item Appearance with Pinput.builder Source: https://context7.com/tkko/flutter_pinput/llms.txt Use Pinput.builder to define custom widgets for each pin item. The builder callback provides access to the pin item's state (value, index, type) to dynamically apply decorations and styles. This example demonstrates conditional styling for different pin item states. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class CustomBuilderExample extends StatefulWidget { const CustomBuilderExample({super.key}); @override State createState() => _CustomBuilderExampleState(); } class _CustomBuilderExampleState extends State { final pinController = TextEditingController(); final focusNode = FocusNode(); final formKey = GlobalKey(); @override void dispose() { pinController.dispose(); focusNode.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Form( key: formKey, child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Pinput.builder( length: 4, controller: pinController, focusNode: focusNode, hapticFeedbackType: HapticFeedbackType.lightImpact, builder: (context, pinState) { // Determine decoration based on pin item state final decoration = switch (pinState.type) { PinItemStateType.disabled => BoxDecoration( borderRadius: BorderRadius.circular(19), border: Border.all(color: Colors.grey), ), PinItemStateType.focused => BoxDecoration( borderRadius: BorderRadius.circular(19), border: Border.all(color: Colors.blue, width: 2), ), PinItemStateType.error => BoxDecoration( borderRadius: BorderRadius.circular(19), border: Border.all(color: Colors.red, width: 2), ), PinItemStateType.submitted => BoxDecoration( borderRadius: BorderRadius.circular(19), color: Colors.green.shade50, border: Border.all(color: Colors.green), ), _ => BoxDecoration( borderRadius: BorderRadius.circular(19), border: Border.all(color: Colors.grey.shade400), ), }; return AnimatedContainer( duration: const Duration(milliseconds: 200), width: 50, height: 50, decoration: decoration, alignment: Alignment.center, child: Text( pinState.value.isEmpty ? '' : pinState.value, style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: pinState.type == PinItemStateType.error ? Colors.red : Colors.black, ), ), ); }, separatorBuilder: (index) => const SizedBox(width: 12), validator: (value) => value == '2222' ? null : 'Pin is incorrect', onCompleted: (pin) => print('Completed: $pin'), ), const SizedBox(height: 20), TextButton( onPressed: () { focusNode.unfocus(); formKey.currentState!.validate(); }, child: const Text('Validate'), ), ], ), ); } } ``` -------------------------------- ### Flutter Pinput Separator Builder Example Source: https://context7.com/tkko/flutter_pinput/llms.txt Adds custom separator widgets between pin fields using the separatorBuilder callback. This is useful for visually grouping digits, like in phone numbers or OTPs. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class SeparatorExample extends StatelessWidget { const SeparatorExample({super.key}); @override Widget build(BuildContext context) { final defaultPinTheme = PinTheme( width: 50, height: 50, textStyle: const TextStyle(fontSize: 20, color: Colors.white), decoration: BoxDecoration( color: Colors.purple.shade300, borderRadius: BorderRadius.circular(8), ), ); return Pinput( length: 6, defaultPinTheme: defaultPinTheme, // Custom separator every field separatorBuilder: (index) { // Add dash separator after 3rd digit (index 2) if (index == 2) { return const Padding( padding: EdgeInsets.symmetric(horizontal: 8), child: Text('-', style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)), ); } return const SizedBox(width: 8); }, onCompleted: (pin) => print('Completed: $pin'), ); } } ``` -------------------------------- ### Firebase Auth SMS Integration with Pinput Source: https://context7.com/tkko/flutter_pinput/llms.txt Integrate Pinput with Firebase Authentication phone verification by setting the controller value in the verificationCompleted callback. This example shows how to handle OTP input and verification. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; import 'package:firebase_auth/firebase_auth.dart'; class FirebasePhoneAuthExample extends StatefulWidget { const FirebasePhoneAuthExample({super.key}); @override State createState() => _FirebasePhoneAuthExampleState(); } class _FirebasePhoneAuthExampleState extends State { final pinController = TextEditingController(); String? verificationId; bool isLoading = false; @override void dispose() { pinController.dispose(); super.dispose(); } Future sendOtp(String phoneNumber) async { setState(() => isLoading = true); await FirebaseAuth.instance.verifyPhoneNumber( phoneNumber: phoneNumber, verificationCompleted: (PhoneAuthCredential credential) { // Auto-fill the SMS code when verification is completed automatically if (credential.smsCode != null) { pinController.setText(credential.smsCode!); } }, verificationFailed: (FirebaseAuthException e) { print('Verification failed: ${e.message}'); setState(() => isLoading = false); }, codeSent: (String verId, int? resendToken) { verificationId = verId; setState(() => isLoading = false); }, codeAutoRetrievalTimeout: (String verId) { verificationId = verId; }, ); } Future verifyOtp(String otp) async { if (verificationId == null) return; try { final credential = PhoneAuthProvider.credential( verificationId: verificationId!, smsCode: otp, ); await FirebaseAuth.instance.signInWithCredential(credential); print('Phone authentication successful!'); } catch (e) { print('Verification error: $e'); } } @override Widget build(BuildContext context) { return Column( children: [ Pinput( length: 6, controller: pinController, autofillHints: const [AutofillHints.oneTimeCode], onCompleted: (pin) => verifyOtp(pin), ), if (isLoading) const CircularProgressIndicator(), ], ); } } ``` -------------------------------- ### System-level Dependencies and Application Target Definition Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/CMakeLists.txt Finds PkgConfig and GTK, defines the application ID, and adds the main executable target with its source files. It also applies standard build settings and links necessary libraries. ```cmake # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") # Define the application target. To change its name, change BINARY_NAME above, # not the value here, or `flutter run` will no longer work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # Add dependency libraries. Add any application-specific dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) # Only the install-generated bundle's copy of the executable will launch # correctly, since the resources must in the right relative locations. To avoid # people trying to run the unbundled copy, put it in a subdirectory instead of # the default top-level location. set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Configure Build Options for Flutter Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt Sets up build configurations (Debug, Profile, Release) for the project. It handles both multi-configuration and single-configuration generators. ```cmake set(BINARY_NAME "example") cmake_policy(SET CMP0063 NEW) set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") # Configure build options. get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Export Flutter Library and ICU Data Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Exports variables for the Flutter library and ICU data file to the parent scope. These are needed for installation and runtime. ```cmake set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) ``` ```cmake set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) ``` ```cmake set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) ``` ```cmake set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) ``` -------------------------------- ### Build a Standard Pinput Widget Source: https://github.com/tkko/flutter_pinput/blob/master/README.md Use this snippet to create a basic Pinput widget. It handles pin input and calls the onCompleted callback when the pin is fully entered. ```dart Widget buildPinPut() { return Pinput( onCompleted: (pin) => print(pin), ); } ``` -------------------------------- ### Configure Pinput Haptic Feedback Source: https://context7.com/tkko/flutter_pinput/llms.txt Demonstrates enabling haptic feedback on pin entry with various intensity options: light, medium, heavy impact, selection click, and vibrate. ```dart import 'package:flutter/material.dart'; import 'package:pinput/pinput.dart'; class HapticFeedbackExample extends StatelessWidget { const HapticFeedbackExample({super.key}); @override Widget build(BuildContext context) { return Column( children: [ // Light impact feedback Pinput( length: 4, hapticFeedbackType: HapticFeedbackType.lightImpact, ), const SizedBox(height: 20), // Medium impact feedback Pinput( length: 4, hapticFeedbackType: HapticFeedbackType.mediumImpact, ), const SizedBox(height: 20), // Heavy impact feedback Pinput( length: 4, hapticFeedbackType: HapticFeedbackType.heavyImpact, ), const SizedBox(height: 20), // Selection click feedback Pinput( length: 4, hapticFeedbackType: HapticFeedbackType.selectionClick, ), const SizedBox(height: 20), // Vibrate feedback Pinput( length: 4, hapticFeedbackType: HapticFeedbackType.vibrate, ), ], ); } } ``` -------------------------------- ### Generated Plugin Build Rules Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/CMakeLists.txt Includes the generated CMake file for plugin registration, which manages building plugins and adding them to the application. ```cmake # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt A function to apply common compilation features, options, and definitions to targets. Ensures consistent build settings across different targets. ```cmake # Use Unicode for all projects. add_definitions(-DUNICODE -D_UNICODE) # Compilation settings that should be applied to most targets. function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") endfunction() ``` -------------------------------- ### Define Wrapper Root Directory Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Sets the root directory for the C++ client wrapper sources. This path is used to locate core wrapper implementation files. ```cmake set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Include Flutter and Plugin Build Rules Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/CMakeLists.txt Includes the necessary CMake files for building the Flutter engine and managing generated plugin build rules. This integrates Flutter's build system into the project. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") # Flutter library and tool build rules. add_subdirectory(${FLUTTER_MANAGED_DIR}) # Application build add_subdirectory("runner") # Generated plugin build rules, which manage building the plugins and adding # them to the application. include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Define Core Wrapper Sources Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Lists the core C++ source files for the Flutter wrapper. These files contain fundamental implementations used by both plugins and the application. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Define Application Wrapper Sources Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Lists the C++ source files for the Flutter application wrapper. These are used when building the main application runner. ```cmake list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Flutter Tool Backend Custom Command Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Configures a custom command to run the Flutter tool backend. This command is responsible for generating Flutter library files and wrapper sources. It uses a phony output file to ensure it runs every time. ```cmake set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ${CPP_WRAPPER_SOURCES_APP} ${PHONY_OUTPUT} COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" windows-x64 $ VERBATIM ) ``` -------------------------------- ### Flutter Library and Tool Build Rules Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/CMakeLists.txt Includes the Flutter managed directory and adds it as a subdirectory for build rules. This is essential for integrating Flutter's build system. ```cmake # Flutter library and tool build rules. set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Customize Focused and Submitted Pin Themes Source: https://github.com/tkko/flutter_pinput/blob/master/README.md Create variations of the default PinTheme for specific states like 'focused' and 'submitted'. This allows for visual feedback during user interaction. ```dart final focusedPinTheme = defaultPinTheme.copyDecorationWith( border: Border.all(color: Color.fromRGBO(114, 178, 238, 1)), borderRadius: BorderRadius.circular(8), ); final submittedPinTheme = defaultPinTheme.copyWith( decoration: defaultPinTheme.decoration.copyWith( color: Color.fromRGBO(234, 239, 243, 1), ), ); ``` -------------------------------- ### Create Flutter interface library Source: https://github.com/tkko/flutter_pinput/blob/master/example/linux/flutter/CMakeLists.txt Defines an interface library for Flutter, setting include directories and linking against the Flutter library and required PkgConfig targets (GTK, GLIB, GIO). ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Define Plugin Wrapper Sources Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Lists the C++ source files specific to the Flutter plugin wrapper. These are used when building plugins that interact with the Flutter engine. ```cmake list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Create Static Library for Plugin Wrapper Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Defines a static library target for the Flutter plugin wrapper. This includes core and plugin-specific sources and links against the Flutter library. ```cmake add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### Include Generated Configuration Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Includes a generated CMake configuration file. This file is typically provided by the Flutter tool and contains project-specific settings. ```cmake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### Create Static Library for Application Wrapper Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/flutter/CMakeLists.txt Defines a static library target for the Flutter application wrapper. This includes core and application-specific sources and links against the Flutter library. ```cmake add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Configure Flutter Windows Executable with CMake Source: https://github.com/tkko/flutter_pinput/blob/master/example/windows/runner/CMakeLists.txt Defines the main executable for a Flutter Windows application, listing source files and linking necessary libraries. Ensure all listed source files and libraries are correctly set up in your project. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) apply_standard_settings(${BINARY_NAME}) target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") add_dependencies(${BINARY_NAME} flutter_assemble) ```