82 lines
2.0 KiB
Dart
82 lines
2.0 KiB
Dart
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(
|
|
create: (context) => MyBloc(),
|
|
child: const MyApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
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: 'CR-Civán',
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: const Color.fromARGB(255, 0, 67, 168)),
|
|
useMaterial3: true,
|
|
),
|
|
home: MyHomePage(
|
|
title: 'COMUNIDAD DE REGANTES DE CIVÁN'
|
|
),
|
|
);
|
|
}
|
|
}
|