mobile_adaptive_learning/lib/features/onboarding/screens/onboarding_screen.dart

181 lines
6.2 KiB
Dart
Raw Normal View History

import 'package:english_learning/features/auth/screens/signup/signup_screen.dart';
2024-08-12 02:17:57 +00:00
import 'package:english_learning/features/onboarding/data/onboarding_data.dart';
import 'package:english_learning/core/widgets/global_button.dart';
import 'package:english_learning/core/widgets/slider_widget.dart';
import 'package:english_learning/core/utils/styles/theme.dart';
2024-08-12 02:17:57 +00:00
import 'package:flutter/material.dart';
class OnBoardingScreen extends StatefulWidget {
const OnBoardingScreen({super.key});
@override
State<OnBoardingScreen> createState() => _OnBoardingScreenState();
}
class _OnBoardingScreenState extends State<OnBoardingScreen> {
final controller = OnBoardingData();
final PageController _pageController = PageController();
int _currentPage = 0;
@override
void dispose() {
_pageController.dispose();
super.dispose();
}
void _onPageChanged(int index) {
setState(() {
_currentPage = index;
});
}
void _nextPage() {
if (_currentPage < controller.onBoardingData.length - 1) {
_pageController.nextPage(
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
2024-08-12 02:17:57 +00:00
);
} else {
// Handle what happens when the onboarding is complete
}
}
void _skipToLastPage() {
_pageController.animateToPage(
controller.onBoardingData.length - 1,
duration: const Duration(milliseconds: 500),
curve: Curves.easeInOut,
2024-08-12 02:17:57 +00:00
);
}
@override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
final screenHeight = mediaQuery.size.height;
2024-08-12 02:17:57 +00:00
return Scaffold(
backgroundColor: AppColors.whiteColor,
2024-08-12 02:17:57 +00:00
body: Column(
children: [
Expanded(
child: PageView.builder(
controller: _pageController,
onPageChanged: _onPageChanged,
itemCount: controller.onBoardingData.length,
itemBuilder: (context, index) {
final item = controller.onBoardingData[index];
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
2024-08-12 02:17:57 +00:00
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2024-08-12 02:17:57 +00:00
children: [
SizedBox(height: screenHeight * 0.15),
Text(
item.title,
style: AppTextStyles.blueTextStyle.copyWith(
fontSize: 30,
fontWeight: FontWeight.w900,
2024-08-12 02:17:57 +00:00
),
),
const SizedBox(height: 4),
2024-08-12 02:17:57 +00:00
Text(
item.description,
style: AppTextStyles.tetriaryTextStyle.copyWith(
2024-08-12 02:17:57 +00:00
fontSize: 14,
fontWeight: FontWeight.w500,
2024-08-12 02:17:57 +00:00
),
),
SizedBox(height: screenHeight * 0.05),
Center(
child: Image.asset(
item.image,
width: item.imageWidth,
height: item.imageHeight,
2024-08-12 02:17:57 +00:00
),
),
],
),
);
},
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
2024-08-12 02:17:57 +00:00
child: Column(
children: [
SliderWidget(
currentPage: _currentPage,
itemCount: controller.onBoardingData.length,
),
SizedBox(height: screenHeight * 0.2),
2024-08-12 02:17:57 +00:00
if (_currentPage == controller.onBoardingData.length - 1)
Column(
children: [
GlobalButton(
text: 'Join Now',
2024-08-12 02:17:57 +00:00
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SignupScreen()),
2024-08-12 02:17:57 +00:00
);
},
),
],
)
else
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: AppColors.disableColor,
width: 0.5,
),
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.0),
),
),
onPressed: _skipToLastPage,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 14.0,
horizontal: 18.0,
),
child: Text(
'Skip',
style: AppTextStyles.disableTextStyle.copyWith(
fontWeight: FontWeight.w500,
),
),
),
),
2024-08-12 02:17:57 +00:00
),
const SizedBox(width: 12),
Expanded(
child: GlobalButton(
text: 'Continue',
icon: Icons.arrow_forward,
onPressed: _nextPage,
spaceBetween: true,
),
),
],
2024-08-12 02:17:57 +00:00
),
],
),
),
SizedBox(height: screenHeight * 0.1),
2024-08-12 02:17:57 +00:00
],
),
);
}
}