feat: Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/features/profile/faq/data/models/faq_entry_model.dart';
|
||||
|
||||
@injectable
|
||||
class FaqApiProvider {
|
||||
static const List<FaqEntryModel> localFaqData = [
|
||||
FaqEntryModel(
|
||||
question: 'How do I create a profile?',
|
||||
answer: 'To create a profile, download the app, sign up with your email '
|
||||
'or phone number, and fill in your basic details, including your '
|
||||
'skills and experience.',
|
||||
),
|
||||
];
|
||||
|
||||
Future<List<FaqEntryModel>> fetchFaqData() async {
|
||||
//TODO: Add additional FAQs either received from the backend or as static local data.
|
||||
return localFaqData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:krow/features/profile/faq/data/faq_api_provider.dart';
|
||||
import 'package:krow/features/profile/faq/data/models/faq_entry_model.dart';
|
||||
import 'package:krow/features/profile/faq/domain/entities/faq_entry.dart';
|
||||
import 'package:krow/features/profile/faq/domain/faq_repository.dart';
|
||||
|
||||
@Injectable(as: FaqRepository)
|
||||
class FaqRepositoryImpl implements FaqRepository {
|
||||
FaqRepositoryImpl({required FaqApiProvider provider}) : _provider = provider;
|
||||
|
||||
final FaqApiProvider _provider;
|
||||
|
||||
FaqEntry _modelConverter(FaqEntryModel data) {
|
||||
return FaqEntry(question: data.question, answer: data.answer);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<FaqEntry>> getFaqData() async {
|
||||
return [
|
||||
for (final entry in await _provider.fetchFaqData())
|
||||
_modelConverter(entry),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
@immutable
|
||||
class FaqEntryModel {
|
||||
const FaqEntryModel({required this.question, required this.answer});
|
||||
|
||||
factory FaqEntryModel.fromJson(Map<String, dynamic> json) {
|
||||
//TODO: Add from JSON conversion once the backend is ready.
|
||||
throw UnimplementedError('Implement from JSON conversion');
|
||||
}
|
||||
|
||||
final String question;
|
||||
final String answer;
|
||||
}
|
||||
Reference in New Issue
Block a user