### Initialize JVerify SDK in Flutter (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Sets up the JVerify SDK with a debug mode, configuration parameters, and a setup callback listener. This snippet is required before any authentication calls and works for both Android and iOS. It returns initialization success or failure via the callback. ```Dart import 'package:jverify/jverify.dart'; final Jverify jverify = Jverify(); // Add SDK setup callback listener before initialization jverify.addSDKSetupCallBackListener((JVSDKSetupEvent event) { if (event.code == 8000) { print("SDK initialized successfully: ${event.message}"); } else { print("SDK initialization failed: ${event.code} - ${event.message}"); } }); // Enable debug mode for development jverify.setDebugMode(true); // Initialize the SDK jverify.setup( appKey: "your_jpush_appkey", // Required for iOS, configured in AndroidManifest for Android channel: "developer-default", // Distribution channel identifier useIDFA: false, // iOS only: whether to use IDFA for analytics timeout: 10000, // Initialization timeout in ms (0-30000], default 10000 setControlWifiSwitch: true // Control WiFi switch setting ); ``` -------------------------------- ### Check JVerify SDK Initialization Status (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Queries the JVerify SDK to determine whether initialization completed successfully. Returns a map containing a boolean flag that can be used to guard subsequent authentication calls. Useful for handling delayed or failed setups. ```Dart // Verify if SDK initialization completed successfully Future checkInitialization() async { Map result = await jverify.isInitSuccess(); bool isInitialized = result["result"]; if (isInitialized) { print("SDK is ready to use"); } else { print("SDK initialization incomplete, retry setup()"); } } ``` -------------------------------- ### One-Tap Login Authorization (Synchronous API) - Dart Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt This snippet demonstrates how to implement one-tap login authorization using the synchronous API in Dart. It includes environment checking, UI configuration, result listener setup, and launching the authorization page. This approach provides immediate feedback upon login completion. ```Dart void performOneClickLogin() async { // Step 1: Check environment Map envCheck = await jverify.checkVerifyEnable(); if (!envCheck["result"]) { print("Network does not support authentication"); return; } // Step 2: Configure UI (see UI Customization section) JVUIConfig uiConfig = JVUIConfig(); uiConfig.navColor = 0xFFFF0000; // Red navigation bar uiConfig.navText = "Login"; uiConfig.logoImgPath = "logo"; // Asset name without extension uiConfig.logBtnText = "Login with Phone Number"; uiConfig.privacyState = true; // Pre-check privacy agreement uiConfig.clauseName = "User Agreement"; uiConfig.clauseUrl = "https://example.com/terms"; uiConfig.clauseNameTwo = "Privacy Policy"; uiConfig.clauseUrlTwo = "https://example.com/privacy"; jverify.setCustomAuthorizationView(false, uiConfig); // Step 3: Add login result listener jverify.addLoginAuthCallBackListener((JVListenerEvent event) { if (event.code == 6000) { String loginToken = event.message; String operator = event.operator; // "CM", "CU", or "CT" print("Login successful, token: $loginToken"); print("Carrier: $operator"); // Send loginToken to backend for phone number retrieval sendTokenToBackend(loginToken); } else { print("Login failed: [${event.code}] ${event.message}"); } }); // Step 4: Add authorization page event listener jverify.addAuthPageEventListener((JVAuthPageEvent event) { print("Auth page event: ${event.code}"); // Event codes: 1000=page present, 1001=page dismiss, etc. }); // Step 5: Launch authorization page (synchronous) jverify.loginAuthSyncApi( autoDismiss: true, // Auto-close page after successful login timeout: 10000 // Request timeout 0-30000ms ); } // Manually close authorization page if needed void closeAuthPage() { jverify.dismissLoginAuthView(); } ``` -------------------------------- ### Creating and Applying Custom JVUIConfig (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt This snippet defines JVUIConfig to customize the JVerify authorization page, including navigation bar, logo positioning, phone number display, slogan, login button styles, privacy agreement with links, background image, status bar settings, and animations. It depends on the jverify Flutter plugin and requires asset images for icons, buttons, and backgrounds. The config is applied via setCustomAuthorizationView, supporting portrait-only or rotation modes, with inputs as config objects and outputs as customized UI views; limitations include platform-specific adjustments for Android/iOS and incomplete landscape config in the example. ```dart // Comprehensive authorization page customization JVUIConfig createCustomUI() { JVUIConfig config = JVUIConfig(); // Navigation bar config.navColor = 0xFF3F51B5; // Indigo background config.navText = "Verify Phone"; // Title text config.navTextColor = 0xFFFFFFFF; // White text config.navReturnImgPath = "back_icon"; // Back button image config.navHidden = false; // Show navigation bar config.navReturnBtnHidden = false; // Show back button config.navTransparent = false; // Opaque navigation // Logo config.logoImgPath = "app_logo"; // Logo image asset config.logoWidth = 120; // Width in dp config.logoHeight = 120; // Height in dp config.logoOffsetY = 50; // Y offset from nav bar bottom config.logoOffsetX = 0; // X offset (0 = center on iOS) config.logoHidden = false; // Show logo // Phone number display config.numberColor = 0xFF212121; // Dark gray text config.numberSize = 24; // Font size config.numFieldOffsetY = 200; // Y offset from nav bar config.numberFieldWidth = 300; // Field width config.numberFieldHeight = 50; // Field height // Slogan text config.sloganOffsetY = 250; // Y offset config.sloganTextColor = 0xFF757575; // Gray text config.sloganTextSize = 14; // Font size config.sloganHidden = false; // Show slogan // Login button config.logBtnText = "Login"; // Button text config.logBtnOffsetY = 320; // Y offset config.logBtnWidth = 300; // Button width config.logBtnHeight = 50; // Button height config.logBtnTextSize = 18; // Text size config.logBtnTextColor = 0xFFFFFFFF; // White text config.loginBtnNormalImage = "btn_normal"; // iOS: normal state config.loginBtnPressedImage = "btn_press"; // iOS: pressed state config.loginBtnUnableImage = "btn_disabled"; // iOS: disabled state config.logBtnBackgroundPath = "btn_bg"; // Android: background image // Privacy agreement config.privacyState = true; // Default checked config.privacyCheckboxHidden = false; // Show checkbox config.checkedImgPath = "checkbox_on"; // Checked image config.uncheckedImgPath = "checkbox_off"; // Unchecked image config.privacyCheckboxSize = 20; // Checkbox size config.privacyCheckboxInCenter = true; // Vertically center with text config.privacyOffsetY = 20; // Distance from bottom config.privacyHintToast = true; // Show toast if unchecked (Android) // Privacy text and links config.privacyText = ["I agree to ", " and ", " and carrier terms"]; config.clauseName = "User Agreement"; // First agreement name config.clauseUrl = "https://example.com/terms"; config.clauseNameTwo = "Privacy Policy"; // Second agreement name config.clauseUrlTwo = "https://example.com/privacy"; config.clauseBaseColor = 0xFF757575; // Normal text color config.clauseColor = 0xFF2196F3; // Link text color config.privacyTextSize = 12; // Text size config.privacyWithBookTitleMark = true; // Add 《》 around carrier terms config.privacyTextCenterGravity = false; // Left-align text // Background config.authBackgroundImage = "auth_bg"; // Background image // Status bar (Android) config.statusBarColorWithNav = true; // Match nav bar color config.statusBarDarkMode = false; // Light status bar config.statusBarTransparent = false; // Opaque status bar config.statusBarHidden = false; // Show status bar config.virtualButtonTransparent = false; // Opaque virtual buttons // Status bar (iOS) config.authStatusBarStyle = JVIOSBarStyle.StatusBarStyleDarkContent; // Animations (Android) config.needStartAnim = true; // Animate on open config.needCloseAnim = true; // Animate on close config.enterAnim = "slide_in_bottom"; // Open animation resource config.exitAnim = "slide_out_bottom"; // Close animation resource // Transition style (iOS) config.modelTransitionStyle = JVIOSUIModalTransitionStyle.CoverVertical; return config; } // Apply UI configuration void applyCustomUI() { JVUIConfig portraitConfig = createCustomUI(); // For portrait-only mode jverify.setCustomAuthorizationView(false, portraitConfig); // For landscape support (Android requires separate landscape config) JVUIConfig landscapeConfig = createCustomUI(); // Adjust landscape-specific offsets... landscapeConfig.logoOffsetY = 30; jverify.setCustomAuthorizationView( true, // Support rotation ``` -------------------------------- ### Flutter JVerify Authentication Service Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Implements phone number verification with carrier authentication and SMS fallback. Handles SDK initialization, UI configuration, and authentication flow. Requires JVerify Flutter plugin and backend verification endpoint. ```dart class AuthenticationService { final Jverify jverify = Jverify(); bool _isInitialized = false; Future initialize() async { jverify.addSDKSetupCallBackListener((JVSDKSetupEvent event) { if (event.code == 8000) { _isInitialized = true; print("JVerify ready"); } }); jverify.setDebugMode(true); jverify.setup( appKey: "your_jpush_appkey", channel: "production", timeout: 10000 ); await Future.delayed(Duration(seconds: 2)); } Future authenticate() async { if (!_isInitialized) { print("SDK not initialized"); return null; } Map envCheck = await jverify.checkVerifyEnable(); if (!envCheck["result"]) { print("Carrier auth unavailable, falling back to SMS"); return await authenticateWithSMS(); } await jverify.preLogin(timeOut: 5000); JVUIConfig config = createAuthUI(); jverify.setCustomAuthorizationView(false, config); Completer completer = Completer(); jverify.addLoginAuthCallBackListener((JVListenerEvent event) { if (event.code == 6000) { completer.complete(event.message); } else { print("Login failed: ${event.code}"); completer.complete(null); } }); jverify.loginAuthSyncApi(autoDismiss: true, timeout: 10000); return completer.future; } Future authenticateWithSMS() async { String phoneNumber = await getPhoneNumberFromUser(); Map result = await jverify.getSMSCode(phoneNum: phoneNumber); if (result["code"] == 3000) { String verificationCode = await getCodeFromUser(); return await verifyCodeOnServer(phoneNumber, verificationCode); } return null; } JVUIConfig createAuthUI() { JVUIConfig config = JVUIConfig(); config.navColor = 0xFF2196F3; config.navText = "Phone Verification"; config.logoImgPath = "app_logo"; config.logBtnText = "Authorize"; config.privacyState = true; config.clauseName = "Terms of Service"; config.clauseUrl = "https://example.com/terms"; return config; } Future verifyTokenOnServer(String token) async { return null; } Future getPhoneNumberFromUser() async { return ""; } Future getCodeFromUser() async { return ""; } Future verifyCodeOnServer(String phone, String code) async { return null; } } ``` ```dart void main() async { WidgetsFlutterBinding.ensureInitialized(); AuthenticationService auth = AuthenticationService(); await auth.initialize(); runApp(MyApp(authService: auth)); } ``` ```dart class LoginScreen extends StatelessWidget { final AuthenticationService authService; LoginScreen({required this.authService}); @override Widget build(BuildContext context) { return Scaffold( body: Center( child: ElevatedButton( onPressed: () async { String? loginToken = await authService.authenticate(); if (loginToken != null) { Navigator.pushReplacementNamed(context, '/home'); } else { showDialog( context: context, builder: (context) => AlertDialog( title: Text("Login Failed"), content: Text("Unable to verify phone number"), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: Text("OK") ) ] ) ); } }, child: Text("Login with Phone"), ), ), ); } } ``` -------------------------------- ### One-Tap Login Authorization (Asynchronous API) - Dart Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Demonstrates asynchronous one-tap login authorization using the `loginAuth` method in Dart. It checks environment, configures UI, launches the authorization flow, and awaits the result. This is a non-blocking call. ```Dart Future performOneClickLoginAsync() async { Map envCheck = await jverify.checkVerifyEnable(); if (!envCheck["result"]) { return; } // Configure UI JVUIConfig uiConfig = JVUIConfig(); uiConfig.navText = "Login"; uiConfig.logBtnText = "Verify Phone Number"; uiConfig.privacyState = true; jverify.setCustomAuthorizationView(false, uiConfig); // Launch and await result Map result = await jverify.loginAuth(true, timeout: 10000); int code = result["code"]; if (code == 6000) { String loginToken = result["message"]; String operator = result["operator"]; print("Login token: $loginToken"); await sendTokenToBackend(loginToken); } else { print("Login failed: [${code}] ${result['message']}"); } } ``` -------------------------------- ### Pre-fetch One-Tap Login Data and Clear Cache (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Executes a pre‑login request to cache phone number data, reducing latency when presenting the one‑tap login UI. Includes a helper to clear the cached pre‑login data. Timeout must be within 3000‑10000 ms; failures are logged. ```Dart // Pre-fetch phone number data to speed up login authorization page Future prepareOneClickLogin() async { // Check network support first Map envCheck = await jverify.checkVerifyEnable(); if (!envCheck["result"]) { return false; } // Pre-login with timeout between 3000-10000ms Map result = await jverify.preLogin(timeOut: 5000); int code = result["code"]; if (code == 7000) { String message = result["message"]; print("Pre-login successful: $message"); return true; } else { print("Pre-login failed: ${result['message']}"); return false; } } // Clear cached pre-login data when needed void clearCache() { jverify.clearPreLoginCache(); } ``` -------------------------------- ### Configure Portrait and Landscape UI in Flutter (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt This snippet sets up custom UI configurations for portrait and landscape orientations in the JVerify authorization view. It requires JVUIConfig objects for each mode and is limited to Android for landscape support. Inputs are config objects; outputs modify the view orientation behavior. ```dart portraitConfig, // Portrait UI landscapeConfig: landscapeConfig // Landscape UI (Android only) ); } ``` -------------------------------- ### Show Login as Centered Popup Dialog in Flutter (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Configures the authorization page as a centered popup dialog with customizable dimensions, offsets, and styling. Depends on JVUIConfig and JVPopViewConfig classes; supports iOS and Android with platform-specific options like corner radius and backdrop opacity. Call loginAuthSyncApi to display; auto-dismiss can be enabled. ```dart // Configure authorization page as centered popup dialog void showLoginAsPopup() { JVUIConfig config = JVUIConfig(); // Basic config... config.navText = "Quick Login"; config.logBtnText = "Authorize"; // Popup configuration JVPopViewConfig popConfig = JVPopViewConfig(); popConfig.width = 340; // Dialog width popConfig.height = 500; // Dialog height popConfig.offsetCenterX = 0; // Horizontal center offset popConfig.offsetCenterY = -50; // Vertical center offset (move up 50dp) popConfig.isBottom = false; // Android: false = center, true = bottom popConfig.popViewCornerRadius = 12.0; // iOS: corner radius popConfig.backgroundAlpha = 0.5; // iOS: backdrop opacity config.popViewConfig = popConfig; jverify.setCustomAuthorizationView(false, config); jverify.loginAuthSyncApi(autoDismiss: true); } ``` -------------------------------- ### Define JVerify error codes constants Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Defines common error codes returned by JVerify APIs for handling authentication results. Includes success codes for token retrieval, SMS code sending, login authentication, pre-login, and SDK initialization. The class provides a method to retrieve human-readable error messages based on error codes. ```Dart // Common error codes returned by JVerify APIs class JVerifyErrorCodes { // Success codes static const int TOKEN_SUCCESS = 2000; // getToken success static const int SMS_SUCCESS = 3000; // getSMSCode success static const int LOGIN_SUCCESS = 6000; // loginAuth success static const int PRELOGIN_SUCCESS = 7000; // preLogin success static const int INIT_SUCCESS = 8000; // setup success // Error code ranges // 1xxx: Verification errors // 2xxx: SDK/network errors (e.g., 2016 = network not supported) // 3xxx: SMS errors (e.g., 3002 = invalid phone number) // 4xxx: Server errors // 5xxx: Server unknown errors // 6xxx: Login errors static String getErrorMessage(int code) { switch (code) { case TOKEN_SUCCESS: return "Token retrieved successfully"; case SMS_SUCCESS: return "SMS code sent successfully"; case LOGIN_SUCCESS: return "Login successful"; case PRELOGIN_SUCCESS: return "Pre-login successful"; case INIT_SUCCESS: return "SDK initialized successfully"; case 2016: return "Network environment does not support authentication"; case 3002: return "Invalid phone number format"; default: return "Error code: $code"; } } } ``` -------------------------------- ### Customize Privacy Web Page in Flutter (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Customizes the appearance of the privacy agreement web page, including navigation bar, titles, and status bar styles for iOS and Android. Returns a JVUIConfig object with color, font, and visibility settings. Limitations include platform-specific options; integrate with setCustomAuthorizationView for use. ```dart // Customize privacy agreement web page appearance JVUIConfig customizePrivacyWebPage() { JVUIConfig config = JVUIConfig(); // Web page navigation bar config.privacyNavColor = 0xFF3F51B5; // Nav bar color config.privacyNavTitleTextColor = 0xFFFFFFFF; // Title color config.privacyNavTitleTextSize = 18; // Title size config.privacyNavReturnBtnImage = "back_white"; // Back button // Web page titles config.privacyNavTitleTitle = "Carrier Agreement"; // iOS: carrier agreement title config.privacyNavTitleTitle1 = "User Agreement"; // Custom agreement 1 title config.privacyNavTitleTitle2 = "Privacy Policy"; // Custom agreement 2 title // Status bar (iOS) config.privacyStatusBarStyle = JVIOSBarStyle.StatusBarStyleLightContent; // Status bar (Android) config.privacyStatusBarColorWithNav = true; // Match nav color config.privacyStatusBarDarkMode = false; // Light content config.privacyStatusBarTransparent = false; // Opaque config.privacyStatusBarHidden = false; // Visible config.privacyVirtualButtonTransparent = false; // Opaque virtual buttons return config; } ``` -------------------------------- ### Add Custom Widgets to Authorization Page in Flutter (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Adds custom text and button widgets to the JVerify authorization UI, including positioning, styling, and click event handling. Requires JVCustomWidget instances and event listeners via addClikWidgetEventListener. Widgets support images, fonts, colors; outputs interactive elements for navigation or dismissal. ```dart // Add custom text and button widgets to authorization page void addCustomWidgets() { JVUIConfig config = JVUIConfig(); config.logBtnText = "Authorize Login"; List widgets = []; // Custom text widget JVCustomWidget textWidget = JVCustomWidget( "custom_text_widget", // Unique widget ID JVCustomWidgetType.textView ); textWidget.title = "Having trouble logging in?"; textWidget.left = 40; // X position from left edge textWidget.top = 400; // Y position from nav bar bottom textWidget.width = 280; textWidget.height = 40; textWidget.titleFont = 14.0; textWidget.titleColor = 0xFF757575; textWidget.backgroundColor = 0xFFF5F5F5; textWidget.textAlignment = JVTextAlignmentType.center; textWidget.isShowUnderline = false; textWidget.isClickEnable = true; // Enable click events textWidget.lines = 1; textWidget.isSingleLine = true; // Add click listener for text widget jverify.addClikWidgetEventListener("custom_text_widget", (widgetId) { print("Custom text clicked: $widgetId"); // Handle click - navigate to help page, etc. }); widgets.add(textWidget); // Custom button widget JVCustomWidget buttonWidget = JVCustomWidget( "use_sms_button", // Unique widget ID JVCustomWidgetType.button ); buttonWidget.title = "Use SMS Verification"; buttonWidget.left = 80; buttonWidget.top = 450; buttonWidget.width = 200; buttonWidget.height = 44; buttonWidget.titleFont = 16.0; buttonWidget.titleColor = 0xFF2196F3; buttonWidget.backgroundColor = 0xFFFFFFFF; buttonWidget.btnNormalImageName = "btn_sms_normal"; // Optional image buttonWidget.btnPressedImageName = "btn_sms_pressed"; // Optional image buttonWidget.isClickEnable = true; // Buttons are clickable by default // Add click listener for button widget jverify.addClikWidgetEventListener("use_sms_button", (widgetId) { print("SMS button clicked"); jverify.dismissLoginAuthView(); // Close auth page // Show SMS verification UI instead }); widgets.add(buttonWidget); // Apply configuration with custom widgets jverify.setCustomAuthorizationView( false, config, widgets: widgets ); } ``` -------------------------------- ### SMS Verification - Dart Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt This snippet illustrates how to request and handle SMS verification codes using the JVerify Flutter plugin in Dart. It configures the SMS request interval and sends a request with optional signature and template IDs. It includes basic error handling. ```Dart void configureSMS() { // Set minimum interval between SMS requests (default 30000ms) jverify.setGetCodeInternal(60000); // 60 seconds between requests } Future sendSMSCode(String phoneNumber) async { Map envCheck = await jverify.checkVerifyEnable(); if (!envCheck["result"]) { print("Network unavailable for SMS verification"); return; } Map result = await jverify.getSMSCode( phoneNum: phoneNumber, signId: "custom_signature_id", // Optional, uses default if null tempId: "custom_template_id" // Optional, uses default if null ); int code = result["code"]; if (code == 3000) { String uuid = result["result"]; String message = result["message"]; print("SMS sent successfully"); print("Request UUID: $uuid"); // User receives SMS code, then verify on backend with uuid // Your backend validates the code with JIGUANG API } else { print("SMS request failed: [${code}] ${result['message']}"); } } ``` -------------------------------- ### Verify Carrier Authentication Availability (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Checks whether the current network environment supports carrier‑based authentication. Returns a boolean indicating support, allowing the app to fall back to SMS verification when necessary. Works on both Android and iOS. ```Dart // Verify if current network supports carrier authentication Future canUseCarrierAuth() async { Map result = await jverify.checkVerifyEnable(); bool isSupported = result["result"]; if (isSupported) { print("Carrier authentication available on current network"); return true; } else { print("Carrier authentication unavailable, use SMS fallback"); return false; } } ``` -------------------------------- ### Retrieve Carrier Authentication Token (Dart) Source: https://context7.com/jpush/jverify-flutter-plugin/llms.txt Attempts to obtain a one‑time authentication token from the carrier network after confirming network support. Returns token, carrier operator, and handles error codes. The token should be sent to a backend server for verification with JIGUANG's API. ```Dart // Retrieve authentication token from carrier network Future authenticateWithToken() async { // First check network support Map envCheck = await jverify.checkVerifyEnable(); if (!envCheck["result"]) { print("Network does not support carrier authentication"); return; } // Get token with optional timeout Map result = await jverify.getToken(timeOut: "5000"); int code = result["code"]; if (code == 2000) { String token = result["message"]; String operator = result["operator"]; // "CM", "CU", or "CT" print("Token obtained: $token"); print("Carrier: $operator"); // Send token to your backend server for verification // Your server validates token with JIGUANG API await verifyTokenOnServer(token); } else { String errorMessage = result["message"]; print("Token retrieval failed: [$code] $errorMessage"); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.