Skip to content
Open
22 changes: 22 additions & 0 deletions lib/core/services/pdf_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:countries_navigator/features/countries/domain/entities/country.dart';

class PdfService {
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;

class PdfService {
pw.Document preparePDF(List<String> data) {
// Implementation for preparing the PDF using the provided data
final pdf = pw.Document();
pdf.addPage(
pw.Page(
build: (pw.Context context) {
return pw.Center(
child: pw.Text(data.join('\n')),
);
},
),
);
return pdf;
}
}
4 changes: 3 additions & 1 deletion lib/core/services/services_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:get_it/get_it.dart';
import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:countries_navigator/core/services/services.dart';
import 'package:countries_navigator/core/services/pdf_service.dart';

GetIt locator = GetIt.instance;

Expand Down Expand Up @@ -78,4 +79,5 @@ Future<void> setupServicesLocator() async {
// locator.registerLazySingleton<SharedPreferences>(() => sharedPreferences);

locator.registerLazySingleton(() => InternetConnectionCheckerPlus());
}
locator.registerLazySingleton(() => PdfService(/* provide necessary arguments here if any */));
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:countries_navigator/core/services/pdf_service.dart';
import 'package:countries_navigator/core/services/services_locator.dart';

class CountryDetailsPage extends StatelessWidget {
const CountryDetailsPage({Key? key, required this.country}) : super(key: key);
Expand Down Expand Up @@ -183,11 +185,14 @@ class CountryDetailsPage extends StatelessWidget {
IconButton(
icon: const Icon(Icons.picture_as_pdf_outlined),
onPressed: () {
BlocProvider.of<CountryDataBloc>(context).add(
GenerateCountryProfileEvent(
country: country,
),
);
try {
// Call the PDF service with the necessary data
final pdfService = locator<PdfService>();
pdfService.generateCountryProfile(country /* provide other necessary arguments here if any */);
} catch (e) {
// Handle exception
print(e);
}
},
),
],
Expand All @@ -204,4 +209,4 @@ class CountryDetailsPage extends StatelessWidget {
),
);
}
}
}