Files
app_notificaciones_ador/lib/main.dart

191 lines
5.2 KiB
Dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:url_launcher/url_launcher.dart';
// Definir eventos
enum Contenedor { noticias, pregon, embalses, tiempo }
// Definir estado
class ContenedoresState {
final Contenedor? currentContenedor;
ContenedoresState({this.currentContenedor});
}
// Definir Bloc
class ContenedoresBloc {
final _stateController = StreamController<ContenedoresState>.broadcast();
Stream<ContenedoresState> get state => _stateController.stream;
void dispose() {
_stateController.close();
}
void selectContenedor(Contenedor contenedor) {
final newState = ContenedoresState(currentContenedor: contenedor);
_stateController.sink.add(newState);
}
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme:
ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 255, 255, 255)),
useMaterial3: true,
),
home: MyHomePage(
title: 'COMUNIDAD DE REGANTES DE CIVÁN',
contenedoresBloc: ContenedoresBloc()
),
);
}
}
class MyHomePage extends StatelessWidget {
final String title;
final ContenedoresBloc contenedoresBloc;
MyHomePage({Key? key, required this.title, required this.contenedoresBloc})
: super(key: key);
Future<void> _launchURL(String url) async {
try {
await launch(url);
} catch (e) {
// Captura de la excepción
print('An error occurred: $e');
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(''),
centerTitle: true,
backgroundColor: const Color.fromARGB(255, 33, 150, 243),
leading: IconButton(
onPressed: () {},
icon: const Icon(Icons.menu),
color: Colors.white,
),
flexibleSpace: Container(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Image.asset(
'assets/logo-civan.png',
height: 150,
width: 150,
),
),
),
),
body: Container(
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/agua.jpg'),
fit: BoxFit.cover,
),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildContenedor(context, 'Noticias'),
_buildContenedor(context, 'Pregón del día'),
_buildContenedor(context, 'Embalses'),
_buildContenedor(context, 'Tiempo'),
],
),
),
),
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.call),
label: 'Llamar',
),
BottomNavigationBarItem(
icon: Icon(Icons.email),
label: 'Correo',
),
],
selectedItemColor: Colors.blue,
unselectedItemColor: Colors.blue,
backgroundColor: const Color.fromARGB(255, 255, 255, 255),
currentIndex: 0,
onTap: (int index) {
if (index == 0) {
// Abre la aplicación de teléfono con el número marcado
_launchURL('tel:+348766361379'); // Reemplazar con el número de teléfono real
} else if (index == 1) {
// Abre la aplicación de correo electrónico
_launchURL('mailto:info@example.com'); // Reemplazar con la dirección de correo electrónico real
}
},
),
);
}
Widget _buildContenedor(BuildContext context, String nombre) {
return InkWell(
onTap: () {
switch (nombre) {
case 'Noticias':
contenedoresBloc.selectContenedor(Contenedor.noticias);
print("Contenedor noticias pulsado");
break;
case 'Pregón del día':
contenedoresBloc.selectContenedor(Contenedor.pregon);
print("Contenedor pregon pulsado");
break;
case 'Embalses':
contenedoresBloc.selectContenedor(Contenedor.embalses);
print("Contenedor embalses pulsado");
break;
case 'Tiempo':
contenedoresBloc.selectContenedor(Contenedor.tiempo);
print("Contenedor tiempo pulsado");
break;
}
},
child: SizedBox(
width: 300.0,
child: Padding(
padding: const EdgeInsets.only(bottom: 20.0),
child: Container(
padding: const EdgeInsets.all(8.0),
decoration: BoxDecoration(
color: nombre == 'Noticias'
? Colors.blue
: const Color.fromRGBO(33, 150, 243, 1),
borderRadius: BorderRadius.circular(7.0),
),
child: Text(
nombre,
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 32.0,
fontWeight: FontWeight.bold,
),
),
),
),
),
);
}
}
void main() {
runApp(const MyApp());
}