// // import 'package:package_info_plus/package_info_plus.dart'; // // import '../../../l10n/app_localizations.dart'; // // import 'package:kmobile/api/services/send_sms_service.dart'; // // import 'package:flutter/material.dart'; // // class SplashScreen extends StatefulWidget { // // const SplashScreen({super.key}); // // @override // // State createState() => _SplashScreenState(); // // } // // class _SplashScreenState extends State { // // String _version = ''; // // final SmsService _smsService = SmsService(); // // @override // // void initState() { // // super.initState(); // // _loadVersion(); // // _sendInitialSms(); // // } // // Future _sendInitialSms() async { // // try { // // await _smsService.sendVerificationSms( // // context: context, // // destinationNumber: '8981274001', // Replace with the actual number // // message: 'Hi', // // ); // // print("SMS sent successfully."); // // } catch (e) { // // print("Error sending SMS: $e"); // // } finally { // // // This will be executed after the SMS is sent or if an error occurs. // // // Replace with your actual navigation logic // // Navigator.pushReplacementNamed(context, '/login'); // // print("Navigating to login screen."); // // } // // } // // Future _loadVersion() async { // // final PackageInfo info = await PackageInfo.fromPlatform(); // // if (mounted) { // // // Check if the widget is still in the tree // // setState(() { // // _version = 'Version ${info.version} (${info.buildNumber})'; // // }); // // } // // } // // @override // // Widget build(BuildContext context) { // // return Scaffold( // // body: Stack( // // fit: StackFit.expand, // // children: [ // // Positioned.fill( // // child: Image.asset( // // 'assets/images/kconnect2.webp', // // fit: BoxFit.cover, // // ), // // ), // // Center( // // child: Column( // // mainAxisSize: MainAxisSize.min, // // children: [ // // Text( // // AppLocalizations.of(context).kccbMobile, // // style: const TextStyle( // // fontSize: 36, // // fontWeight: FontWeight.bold, // // color: Color(0xFFFFFFFF), // // ), // // ), // // const SizedBox(height: 12), // // Text( // // AppLocalizations.of(context).kccBankFull, // // textAlign: TextAlign.center, // // style: const TextStyle( // // fontSize: 18, // // color: Color(0xFFFFFFFF), // // letterSpacing: 1.2, // // ), // // ), // // ], // // ), // // ), // // const Positioned( // // bottom: 40, // // left: 0, // // right: 0, // // child: Center( // // child: CircularProgressIndicator(color: Color(0xFFFFFFFF)), // // ), // // ), // // Positioned( // // bottom: 90, // // left: 0, // // right: 0, // // child: Text( // // _version, // // textAlign: TextAlign.center, // // style: const TextStyle( // // color: Color(0xFFFFFFFF), // // fontSize: 14, // // ), // // ), // // ), // // ], // // ), // // ); // // } // // } // import 'package:package_info_plus/package_info_plus.dart'; // import 'package:kmobile/l10n/app_localizations.dart'; // import 'package:kmobile/api/services/send_sms_service.dart'; // import 'package:flutter/material.dart'; // class SplashScreen extends StatefulWidget { // const SplashScreen({super.key}); // @override // State createState() => _SplashScreenState(); // } // class _SplashScreenState extends State { // String _version = ''; // final SmsService _smsService = SmsService(); // @override // void initState() { // super.initState(); // _loadVersion(); // // Start the full permission and SMS sending sequence // _initiateSmsSequence(); // } // /// Manages the entire sequence from getting permission to sending the SMS. // Future _initiateSmsSequence() async { // bool hasPermission = false; // // --- PERMISSION LOOP --- // // First, loop until the necessary permissions are granted. // while (!hasPermission) { // print("Checking for SMS permission..."); // hasPermission = await _smsService.handleSmsPermission(); // if (hasPermission) { // print("Permission granted! Proceeding to send SMS."); // break; // Exit the permission loop // } else { // print("Permission not granted. Will re-check in 5 seconds. Please grant permission in settings if prompted."); // // Wait for 5 seconds. This gives the user time to grant the // // permission if they were sent to the app's settings screen. // await Future.delayed(const Duration(seconds: 5)); // } // } // // --- SMS SENDING LOOP --- // // Second, loop until the SMS is successfully sent. // bool isSmsSent = false; // while (!isSmsSent) { // print("Attempting to send SMS..."); // isSmsSent = await _smsService.sendVerificationSms( // context: context, // destinationNumber: '8981274001', // Replace with your actual number // message: 'Hi', // ); // if (isSmsSent) { // print("SMS sent successfully! Proceeding to login."); // break; // Exit the SMS sending loop // } else { // print("SMS failed to send. Retrying in 5 seconds..."); // await Future.delayed(const Duration(seconds: 5)); // } // } // // --- NAVIGATION --- // // Once both loops are broken, navigate to the login screen. // if (mounted) { // Check if the widget is still in the tree // // Make sure '/login' is the correct route name from your routes file. // Navigator.pushReplacementNamed(context, '/login'); // } // } // Future _loadVersion() async { // final PackageInfo info = await PackageInfo.fromPlatform(); // if (mounted) { // setState(() { // _version = 'Version ${info.version} (${info.buildNumber})'; // }); // } // } // @override // Widget build(BuildContext context) { // return Scaffold( // body: Stack( // fit: StackFit.expand, // children: [ // Positioned.fill( // child: Image.asset( // 'assets/images/kconnect2.webp', // fit: BoxFit.cover, // ), // ), // Center( // child: Column( // mainAxisSize: MainAxisSize.min, // children: [ // Text( // AppLocalizations.of(context).kccbMobile, // style: const TextStyle( // fontSize: 36, // fontWeight: FontWeight.bold, // color: Color(0xFFFFFFFF), // ), // ), // const SizedBox(height: 12), // Text( // AppLocalizations.of(context).kccBankFull, // textAlign: TextAlign.center, // style: const TextStyle( // fontSize: 18, // color: Color(0xFFFFFFFF), // letterSpacing: 1.2, // ), // ), // ], // ), // ), // const Positioned( // bottom: 40, // left: 0, // right: 0, // child: Center( // child: CircularProgressIndicator(color: Color(0xFFFFFFFF)), // ), // ), // Positioned( // bottom: 90, // left: 0, // right: 0, // child: Text( // _version, // textAlign: TextAlign.center, // style: const TextStyle( // color: Color(0xFFFFFFFF), // fontSize: 14, // ), // ), // ), // ], // ), // ); // } // } import 'package:flutter/material.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:kmobile/l10n/app_localizations.dart'; class SplashScreen extends StatefulWidget { const SplashScreen({super.key}); @override State createState() => _SplashScreenState(); } class _SplashScreenState extends State { String _version = ''; @override void initState() { super.initState(); _loadVersion(); } Future _loadVersion() async { final PackageInfo info = await PackageInfo.fromPlatform(); if (mounted) { setState(() { _version = 'Version ${info.version} (${info.buildNumber})'; }); } } @override Widget build(BuildContext context) { // This build method is the same, but all the SMS logic is gone. return Scaffold( body: Stack( fit: StackFit.expand, children: [ Positioned.fill( child: Image.asset( 'assets/images/kconnect2.webp', fit: BoxFit.cover, ), ), Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Text( AppLocalizations.of(context).kccbMobile, style: const TextStyle( fontSize: 36, fontWeight: FontWeight.bold, color: Color(0xFFFFFFFF), ), ), const SizedBox(height: 12), Text( AppLocalizations.of(context).kccBankFull, textAlign: TextAlign.center, style: const TextStyle( fontSize: 18, color: Color(0xFFFFFFFF), letterSpacing: 1.2, ), ), ], ), ), const Positioned( bottom: 40, left: 0, right: 0, child: Center( child: CircularProgressIndicator(color: Color(0xFFFFFFFF)), ), ), Positioned( bottom: 90, left: 0, right: 0, child: Text( _version, textAlign: TextAlign.center, style: const TextStyle( color: Color(0xFFFFFFFF), fontSize: 14, ), ), ), ], ), ); } }