import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:injector/injector.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:prosappco/components/general_drawer_item.dart'; import 'package:prosappco/screens/web/web_view_screen.dart'; import 'package:setting_repository/setting_repository.dart'; import 'package:url_launcher/url_launcher.dart'; import 'dart:io' show Platform; class ConfigurationAboutScreen extends StatefulWidget { const ConfigurationAboutScreen({super.key}); @override State createState() => _ConfigurationAboutScreenState(); } class _ConfigurationAboutScreenState extends State { final settingRepository = Injector.appInstance.get(); SettingEntity? settings; @override void initState() { super.initState(); _loadSettings(); } void _loadSettings() { settingRepository.getSettings().then( (value) => setState(() { settings = value; }), ); } void _launchURL(String url) async { if (await canLaunch(url)) { await launch(url, forceSafariVC: false, forceWebView: false); } else { throw 'No se pudo abrir el enlace $url'; } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Acerca de la aplicación'), ), body: ListView( children: [ GeneralDrawerItem( label: 'Políticas de privacidad', onTap: () { if (kIsWeb) { _launchURL(settings?.politicasPrivacidad ?? ''); } else { Navigator.push( context, CupertinoPageRoute( builder: (BuildContext context) { return WebViewScreen( label: 'Políticas de privacidad', link: settings?.politicasPrivacidad ?? '', ); }, ), ); } }, trailing: true, ), GeneralDrawerItem( label: 'Términos y condiciones', onTap: () { if (kIsWeb) { _launchURL(settings?.terminosCondiciones ?? ''); } else { Navigator.push( context, CupertinoPageRoute( builder: (BuildContext context) { return WebViewScreen( label: 'Términos y condiciones', link: settings?.terminosCondiciones ?? '', ); }, ), ); } }, trailing: true, ), Platform.isIOS ? GeneralDrawerItem( label: 'Versión de la aplicación', subtitle: settings?.versionIos, ) : Container(), Platform.isAndroid ? GeneralDrawerItem( label: 'Versión de la aplicación', subtitle: settings?.versionAndroid, ) : Container(), ], ), ); } }