first commit
This commit is contained in:
191
lib/Screens/SplashScreen/on_board.dart
Normal file
191
lib/Screens/SplashScreen/on_board.dart
Normal file
@@ -0,0 +1,191 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_pos/core/theme/_app_colors.dart';
|
||||
import 'package:mobile_pos/generated/l10n.dart' as lang;
|
||||
import 'package:nb_utils/nb_utils.dart';
|
||||
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
|
||||
|
||||
import '../../constant.dart';
|
||||
import '../Authentication/Sign In/sign_in_screen.dart';
|
||||
|
||||
class OnBoard extends StatefulWidget {
|
||||
const OnBoard({super.key});
|
||||
|
||||
@override
|
||||
// ignore: library_private_types_in_public_api
|
||||
_OnBoardState createState() => _OnBoardState();
|
||||
}
|
||||
|
||||
class _OnBoardState extends State<OnBoard> {
|
||||
PageController pageController = PageController(initialPage: 0);
|
||||
int currentIndexPage = 0;
|
||||
String buttonText = 'Next';
|
||||
|
||||
List<Map<String, dynamic>> getSlider({required BuildContext context}) {
|
||||
List<Map<String, dynamic>> sliderList = [
|
||||
{
|
||||
"icon": onboard1,
|
||||
"title": lang.S.of(context).easyToUseThePos,
|
||||
"description": lang.S.of(context).easytheusedesciption,
|
||||
},
|
||||
{
|
||||
"icon": onboard2,
|
||||
"title": lang.S.of(context).choseYourFeature,
|
||||
"description": lang.S.of(context).choseyourfeatureDesciption,
|
||||
},
|
||||
{
|
||||
"icon": onboard3,
|
||||
"title": lang.S.of(context).allBusinessSolutions,
|
||||
"description": lang.S.of(context).allBusinessolutionDescrip,
|
||||
},
|
||||
];
|
||||
return sliderList;
|
||||
}
|
||||
|
||||
List<Map<String, dynamic>> sliderList = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final _theme = Theme.of(context);
|
||||
sliderList = getSlider(context: context);
|
||||
return Scaffold(
|
||||
backgroundColor: kWhite,
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
const SizedBox(height: 30),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SignIn(),
|
||||
));
|
||||
},
|
||||
child: Text(
|
||||
lang.S.of(context).skip,
|
||||
style: _theme.textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(top: 20, bottom: 20),
|
||||
width: context.width(),
|
||||
child: Stack(
|
||||
alignment: Alignment.bottomCenter,
|
||||
children: [
|
||||
PageView.builder(
|
||||
itemCount: sliderList.length,
|
||||
controller: pageController,
|
||||
onPageChanged: (int index) => setState(() => currentIndexPage = index),
|
||||
itemBuilder: (_, index) {
|
||||
return Column(
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
Expanded(
|
||||
child: Image.asset(
|
||||
sliderList[index]['icon'],
|
||||
fit: BoxFit.contain,
|
||||
width: context.width() - 100,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Text(
|
||||
sliderList[index]['title'].toString(),
|
||||
style: _theme.textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
// ignore: sized_box_for_whitespace
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 20.0, right: 20.0),
|
||||
// ignore: sized_box_for_whitespace
|
||||
child: Container(
|
||||
width: context.width(),
|
||||
child: Text(
|
||||
sliderList[index]['description'].toString(),
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 5,
|
||||
style: _theme.textTheme.bodyLarge?.copyWith(
|
||||
color: DAppColors.kNeutral700,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: SmoothPageIndicator(
|
||||
controller: pageController,
|
||||
count: sliderList.length,
|
||||
effect: ExpandingDotsEffect(dotColor: kMainColor.withOpacity(0.2), activeDotColor: kMainColor, dotHeight: 8, dotWidth: 8),
|
||||
),
|
||||
),
|
||||
// DotIndicator(
|
||||
// currentDotSize: 25,
|
||||
// dotSize: 6,
|
||||
// pageController: pageController,
|
||||
// pages: sliderList,
|
||||
// indicatorColor: kMainColor,
|
||||
// unselectedIndicatorColor: Colors.grey,
|
||||
// ),
|
||||
// const Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: ElevatedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
maximumSize: const Size(double.infinity, 48),
|
||||
minimumSize: const Size(double.infinity, 48),
|
||||
disabledBackgroundColor: _theme.colorScheme.primary.withValues(alpha: 0.15),
|
||||
disabledForegroundColor: const Color(0xff567DF4).withOpacity(0.05),
|
||||
),
|
||||
onPressed: () {
|
||||
setState(
|
||||
() {
|
||||
currentIndexPage < 2
|
||||
? pageController.nextPage(duration: const Duration(microseconds: 1000), curve: Curves.bounceInOut)
|
||||
: Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const SignIn(),
|
||||
));
|
||||
// : const SignInScreen().launch(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_forward,
|
||||
color: Colors.white,
|
||||
),
|
||||
iconAlignment: IconAlignment.end,
|
||||
label: Text(
|
||||
lang.S.of(context).next,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: _theme.textTheme.bodyMedium?.copyWith(
|
||||
color: _theme.colorScheme.primaryContainer,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
147
lib/Screens/SplashScreen/splash_screen.dart
Normal file
147
lib/Screens/SplashScreen/splash_screen.dart
Normal file
@@ -0,0 +1,147 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
|
||||
import 'package:mobile_pos/Screens/SplashScreen/on_board.dart';
|
||||
import 'package:mobile_pos/constant.dart';
|
||||
import 'package:mobile_pos/generated/l10n.dart' as lang;
|
||||
import 'package:nb_utils/nb_utils.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../Repository/API/business_info_repo.dart';
|
||||
import '../../core/constant_variables/local_data_saving_keys.dart';
|
||||
import '../../currency.dart';
|
||||
import '../Authentication/Repo/licnese_repo.dart';
|
||||
import '../Authentication/Sign In/sign_in_screen.dart';
|
||||
import '../Home/home.dart';
|
||||
import '../language/language_provider.dart';
|
||||
|
||||
class SplashScreen extends ConsumerStatefulWidget {
|
||||
const SplashScreen({super.key});
|
||||
|
||||
@override
|
||||
SplashScreenState createState() => SplashScreenState();
|
||||
}
|
||||
|
||||
class SplashScreenState extends ConsumerState<SplashScreen> {
|
||||
void getPermission() async {
|
||||
Map<Permission, PermissionStatus> statuses = await [
|
||||
Permission.bluetoothScan,
|
||||
Permission.bluetoothConnect,
|
||||
].request();
|
||||
}
|
||||
|
||||
int retryCount = 0;
|
||||
|
||||
Future<void> checkUserValidity() async {
|
||||
final bool isConnected = await InternetConnection().hasInternetAccess;
|
||||
if (isConnected) {
|
||||
nextPage();
|
||||
} else {
|
||||
if (retryCount < 3) {
|
||||
retryCount++;
|
||||
checkUserValidity();
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(lang.S.of(context).notInternetConnection),
|
||||
content: Text(lang.S.of(context).pleaseCheckYourInternetConnection),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
checkUserValidity();
|
||||
},
|
||||
child: Text(lang.S.of(context).ok),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getPermission();
|
||||
CurrencyMethods().getCurrencyFromLocalDatabase();
|
||||
checkUserValidity();
|
||||
setLanguage();
|
||||
}
|
||||
|
||||
Future<void> setLanguage() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final savedLanguageCode = prefs.getString('lang') ?? 'en'; // Default to English code
|
||||
setState(() {
|
||||
selectedLanguage = savedLanguageCode;
|
||||
});
|
||||
context.read<LanguageChangeProvider>().changeLocale(savedLanguageCode);
|
||||
}
|
||||
|
||||
Future<void> nextPage() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
final token = prefs.getString(LocalDataBaseSavingKey.tokenKey);
|
||||
final skipOnBoard = prefs.getBool(LocalDataBaseSavingKey.skipOnBodingKey) ?? false;
|
||||
|
||||
if (token == null) {
|
||||
CurrencyMethods().removeCurrencyFromLocalDatabase();
|
||||
return _goTo(skipOnBoard ? const SignIn() : const OnBoard());
|
||||
}
|
||||
|
||||
final data = await BusinessRepository().checkBusinessData();
|
||||
_goTo(data == null ? (skipOnBoard ? const SignIn() : const OnBoard()) : const Home());
|
||||
}
|
||||
|
||||
void _goTo(Widget page) {
|
||||
Navigator.pushReplacement(context, MaterialPageRoute(builder: (_) => page));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
backgroundColor: kMainColor,
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Spacer(),
|
||||
Container(
|
||||
height: 230,
|
||||
width: 230,
|
||||
decoration: const BoxDecoration(image: DecorationImage(image: AssetImage(splashLogo))),
|
||||
),
|
||||
const Spacer(),
|
||||
Center(
|
||||
child: Text(
|
||||
'${lang.S.of(context).poweredBy} $companyName',
|
||||
style: theme.textTheme.titleLarge
|
||||
?.copyWith(color: Colors.white, fontWeight: FontWeight.w500, fontSize: 18),
|
||||
),
|
||||
),
|
||||
// Center(
|
||||
// child: Text(
|
||||
// 'V $appVersion',
|
||||
// style: theme.textTheme.titleLarge?.copyWith(
|
||||
// color: Colors.white,
|
||||
// fontWeight: FontWeight.w500,
|
||||
// fontSize: 18,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user