Cambios para pwa
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
import 'dart:html' as html;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:crcivan/BloC/contenedores_event.dart';
|
||||
import '../pages/my_home_page.dart';
|
||||
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
BlocProvider(
|
||||
@ -13,18 +14,68 @@ void main() {
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
_MyAppState createState() => _MyAppState();
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
html.BeforeInstallPromptEvent? deferredPrompt;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_detectInstallPrompt();
|
||||
}
|
||||
|
||||
void _detectInstallPrompt() {
|
||||
html.window.addEventListener('beforeinstallprompt', (event) {
|
||||
event.preventDefault();
|
||||
setState(() {
|
||||
deferredPrompt = event as html.BeforeInstallPromptEvent;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _showInstallDialog() {
|
||||
if (deferredPrompt != null) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text("Instalar CR-Civán"),
|
||||
content: Text("Añade esta app a tu pantalla de inicio para una mejor experiencia."),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
deferredPrompt!.prompt();
|
||||
deferredPrompt = null;
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text("Instalar"),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text("Más tarde"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
title: 'CR-Civán',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: const Color.fromARGB(255, 0, 67, 168)),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'COMUNIDAD DE REGANTES DE CIVÁN'),
|
||||
home: MyHomePage(
|
||||
title: 'COMUNIDAD DE REGANTES DE CIVÁN'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user