178 lines
6.2 KiB
Dart
178 lines
6.2 KiB
Dart
import 'package:english_learning/features/auth/screens/signup_screen.dart';
|
|
import 'package:english_learning/features/onboarding/data/onboarding_data.dart';
|
|
import 'package:english_learning/features/widgets/gradient_button.dart';
|
|
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: 300),
|
|
curve: Curves.easeIn,
|
|
);
|
|
} else {
|
|
// Handle what happens when the onboarding is complete
|
|
}
|
|
}
|
|
|
|
void _skipToLastPage() {
|
|
_pageController.animateToPage(
|
|
controller.onBoardingData.length - 1,
|
|
duration: const Duration(milliseconds: 300),
|
|
curve: Curves.easeIn,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
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, vertical: 24.0),
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const SizedBox(height: 100),
|
|
ShaderMask(
|
|
shaderCallback: (bounds) => const LinearGradient(
|
|
colors: [
|
|
Color(0xFF5674ED),
|
|
Color(0xFF34C3F9),
|
|
],
|
|
).createShader(
|
|
Rect.fromLTWH(0, 0, bounds.width, bounds.height),
|
|
),
|
|
child: Text(
|
|
item.title,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
item.description,
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w400,
|
|
height: 1.5,
|
|
),
|
|
),
|
|
const Spacer(flex: 2),
|
|
Image.asset(
|
|
item.image,
|
|
width: item.imageWidth,
|
|
height: item.imageHeight,
|
|
),
|
|
const SizedBox(height: 70),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: List.generate(
|
|
controller.onBoardingData.length,
|
|
(index) => AnimatedContainer(
|
|
duration: const Duration(milliseconds: 300),
|
|
margin: const EdgeInsets.symmetric(horizontal: 4.0),
|
|
height: 8,
|
|
width: _currentPage == index ? 24 : 8,
|
|
decoration: BoxDecoration(
|
|
color: _currentPage == index
|
|
? const Color(0xFF34C3F9)
|
|
: const Color(0xFFD8D8D8),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const Spacer(
|
|
flex: 1), // Added Spacer for better alignment
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
Padding(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
|
|
child: Column(
|
|
children: [
|
|
if (_currentPage == controller.onBoardingData.length - 1)
|
|
Column(
|
|
children: [
|
|
GradientButton(
|
|
text: 'Sign Up',
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const SignupScreen()),
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 48), // Same height as the Spacer
|
|
],
|
|
)
|
|
else
|
|
GradientButton(
|
|
text: 'Continue',
|
|
onPressed: _nextPage,
|
|
),
|
|
const SizedBox(
|
|
height: 16), // Add some space between the buttons
|
|
if (_currentPage != controller.onBoardingData.length - 1)
|
|
TextButton(
|
|
onPressed: _skipToLastPage,
|
|
child: const Text(
|
|
'Skip',
|
|
style: TextStyle(
|
|
color: Color(0xFF34C3F9),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 50),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|