agregado patron bloc y barra de contacto
This commit is contained in:
308
lib/main.dart
308
lib/main.dart
@ -1,7 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
// 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 {
|
||||
@ -13,174 +37,154 @@ class MyApp extends StatelessWidget {
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
colorScheme:
|
||||
ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 0, 67, 168)),
|
||||
ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 255, 255, 255)),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'COMUNIDAD DE REGANTES DE CIVÁN'),
|
||||
home: MyHomePage(
|
||||
title: 'COMUNIDAD DE REGANTES DE CIVÁN',
|
||||
contenedoresBloc: ContenedoresBloc()
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({Key? key, required this.title}) : super(key: key);
|
||||
class MyHomePage extends StatelessWidget {
|
||||
final String title;
|
||||
final ContenedoresBloc contenedoresBloc;
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
|
||||
@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,
|
||||
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,
|
||||
),
|
||||
),
|
||||
flexibleSpace: Container(
|
||||
),
|
||||
),
|
||||
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),
|
||||
child: Center(
|
||||
child: Image.asset(
|
||||
'assets/logo-civan.png',
|
||||
height: 200, // Cambia la altura según sea necesario
|
||||
width: 200, // Cambia el ancho según sea necesario
|
||||
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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image:
|
||||
AssetImage('assets/agua.jpg'), // Ruta de la imagen de fondo
|
||||
fit: BoxFit
|
||||
.cover, // Ajusta la imagen para que cubra todo el contenedor
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
InkWell(
|
||||
onTap: () {
|
||||
print('Contenedor noticias clickeado');
|
||||
},
|
||||
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: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(7.0),
|
||||
),
|
||||
child: const Text(
|
||||
'Noticias',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
print('Contenedor pregón clickeado');
|
||||
},
|
||||
customBorder: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(100)),
|
||||
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: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(7.0),
|
||||
),
|
||||
child: const Text(
|
||||
'Pregón del día',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
print('Contenedor embalses clickeado');
|
||||
},
|
||||
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: const Color.fromRGBO(33, 150, 243, 1),
|
||||
borderRadius: BorderRadius.circular(7.0),
|
||||
),
|
||||
child: const Text(
|
||||
'Embalses',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
print('Contenedor tiempo clickeado');
|
||||
},
|
||||
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: const Color.fromRGBO(33, 150, 243, 1),
|
||||
borderRadius: BorderRadius.circular(7.0),
|
||||
),
|
||||
child: const Text(
|
||||
'Tiempo',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 32.0,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user