2024-10-10 05:49:33 +00:00
|
|
|
import 'package:english_learning/features/auth/provider/user_provider.dart';
|
|
|
|
|
import 'package:english_learning/features/learning/provider/section_provider.dart';
|
|
|
|
|
import 'package:english_learning/features/learning/widgets/section_card.dart';
|
|
|
|
|
import 'package:english_learning/features/learning/modules/topics/screens/topics_list_screen.dart';
|
2024-11-23 10:28:23 +00:00
|
|
|
import 'package:english_learning/features/learning/widgets/section_card_loading.dart';
|
2024-10-10 05:49:33 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:english_learning/core/utils/styles/theme.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class LearningScreen extends StatefulWidget {
|
|
|
|
|
const LearningScreen({
|
|
|
|
|
super.key,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<LearningScreen> createState() => _LearningScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _LearningScreenState extends State<LearningScreen> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2024-11-13 02:03:40 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
_fetchSections();
|
|
|
|
|
});
|
2024-10-10 05:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _fetchSections() async {
|
|
|
|
|
final userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
|
|
|
final token = await userProvider.getValidToken();
|
|
|
|
|
|
|
|
|
|
if (token != null) {
|
|
|
|
|
await Provider.of<SectionProvider>(context, listen: false)
|
|
|
|
|
.fetchSections(token);
|
|
|
|
|
} else {
|
|
|
|
|
print('No valid token found. User might need to log in.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: AppColors.bgSoftColor,
|
|
|
|
|
body: SafeArea(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 28.0, left: 16.0, right: 16.0),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Choose what you want to learn!',
|
|
|
|
|
style: AppTextStyles.blueTextStyle.copyWith(
|
|
|
|
|
fontSize: 18,
|
|
|
|
|
fontWeight: FontWeight.w900,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
Text(
|
|
|
|
|
'Develop your English skills by studying the topics in each section below.',
|
|
|
|
|
style: AppTextStyles.greyTextStyle.copyWith(
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 15),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Consumer<SectionProvider>(
|
|
|
|
|
builder: (context, sectionProvider, _) {
|
|
|
|
|
if (sectionProvider.isLoading) {
|
2024-11-23 10:28:23 +00:00
|
|
|
return ListView.builder(
|
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
|
itemCount: 6,
|
|
|
|
|
itemBuilder: (context, index) =>
|
|
|
|
|
const SectionCardLoading(),
|
|
|
|
|
);
|
2024-10-10 05:49:33 +00:00
|
|
|
} else if (sectionProvider.error != null) {
|
|
|
|
|
return Center(
|
Updated various files, including constants, exercise providers, question widgets, section models, and screens for topics, learning, and settings, with changes to URLs, error handling, and UI components.
2024-11-21 05:45:41 +00:00
|
|
|
child: Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
'Error: ${sectionProvider.error}',
|
|
|
|
|
style: AppTextStyles.greyTextStyle,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(height: 16),
|
|
|
|
|
// Tambahkan tombol retry jika diperlukan
|
|
|
|
|
ElevatedButton(
|
|
|
|
|
onPressed: _fetchSections,
|
|
|
|
|
child: Text('Retry'),
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
));
|
|
|
|
|
} else if (sectionProvider.sections.isEmpty) {
|
|
|
|
|
return Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
'No sections available',
|
|
|
|
|
style: AppTextStyles.greyTextStyle,
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-10-10 05:49:33 +00:00
|
|
|
} else {
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
itemCount: sectionProvider.sections.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final section = sectionProvider.sections[index];
|
2024-11-23 10:28:23 +00:00
|
|
|
return SectionCard(
|
2024-10-10 05:49:33 +00:00
|
|
|
section: section,
|
|
|
|
|
onTap: () => Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => TopicsListScreen(
|
|
|
|
|
sectionId: section.id,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|