diff --git a/lib/core/services/pdf_service.dart b/lib/core/services/pdf_service.dart new file mode 100644 index 0000000..82dd180 --- /dev/null +++ b/lib/core/services/pdf_service.dart @@ -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 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; + } + } \ No newline at end of file diff --git a/lib/core/services/services_locator.dart b/lib/core/services/services_locator.dart index d9a67b7..b42e621 100644 --- a/lib/core/services/services_locator.dart +++ b/lib/core/services/services_locator.dart @@ -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; @@ -78,4 +79,5 @@ Future setupServicesLocator() async { // locator.registerLazySingleton(() => sharedPreferences); locator.registerLazySingleton(() => InternetConnectionCheckerPlus()); -} + locator.registerLazySingleton(() => PdfService(/* provide necessary arguments here if any */)); +} \ No newline at end of file diff --git a/lib/features/countries/presentation/pages/country_details_page.dart b/lib/features/countries/presentation/pages/country_details_page.dart index 95365cf..e2c3d51 100644 --- a/lib/features/countries/presentation/pages/country_details_page.dart +++ b/lib/features/countries/presentation/pages/country_details_page.dart @@ -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); @@ -183,11 +185,14 @@ class CountryDetailsPage extends StatelessWidget { IconButton( icon: const Icon(Icons.picture_as_pdf_outlined), onPressed: () { - BlocProvider.of(context).add( - GenerateCountryProfileEvent( - country: country, - ), - ); + try { + // Call the PDF service with the necessary data + final pdfService = locator(); + pdfService.generateCountryProfile(country /* provide other necessary arguments here if any */); + } catch (e) { + // Handle exception + print(e); + } }, ), ], @@ -204,4 +209,4 @@ class CountryDetailsPage extends StatelessWidget { ), ); } -} +} \ No newline at end of file