Patron bloc integrado
This commit is contained in:
BIN
assets/logo-fondo.png
Normal file
BIN
assets/logo-fondo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
BIN
lib/assets/logo-fondo.png
Normal file
BIN
lib/assets/logo-fondo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
16
lib/contenedores_bloc.dart
Normal file
16
lib/contenedores_bloc.dart
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'package:flutter\_bloc/flutter\_bloc.dart';
|
||||||
|
|
||||||
|
|
||||||
|
import 'package:flutter_project/contenedores_event.dart';
|
||||||
|
import 'package:flutter_project/contenedores_state.dart';
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
class ContenedoresBloc extends Bloc<ContenedoresEvent, ContenedoresState> {
|
||||||
|
ContenedoresBloc() : super(const ContenedoresState()) {
|
||||||
|
on<SelectContenedor>((event, emit) {
|
||||||
|
emit(ContenedoresState(currentContenedor: event.contenedor));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}*/
|
||||||
12
lib/contenedores_event.dart
Normal file
12
lib/contenedores_event.dart
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
// Define el estado
|
||||||
|
class MyState {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define el bloc
|
||||||
|
class MyBloc extends Cubit<MyState> {
|
||||||
|
MyBloc() : super(MyState());
|
||||||
|
|
||||||
|
}
|
||||||
8
lib/contenedores_state.dart
Normal file
8
lib/contenedores_state.dart
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// This class represents the state of the ContenedoresBloc
|
||||||
|
/*import 'package:flutter_project/contenedores_event.dart';
|
||||||
|
|
||||||
|
class ContenedoresState {
|
||||||
|
final Contenedor? currentContenedor;
|
||||||
|
|
||||||
|
const ContenedoresState({this.currentContenedor});
|
||||||
|
}*/
|
||||||
185
lib/main.dart
185
lib/main.dart
@ -1,31 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:async';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:flutter_project/contenedores_event.dart';
|
||||||
|
import 'my_home_page.dart';
|
||||||
|
|
||||||
// Definir eventos
|
void main() {
|
||||||
enum Contenedor { noticias, pregon, embalses, tiempo }
|
runApp(
|
||||||
|
BlocProvider(
|
||||||
// Definir estado
|
create: (context) => MyBloc(),
|
||||||
class ContenedoresState {
|
child: const MyApp(),
|
||||||
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 {
|
class MyApp extends StatelessWidget {
|
||||||
@ -36,155 +20,10 @@ class MyApp extends StatelessWidget {
|
|||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Flutter Demo',
|
title: 'Flutter Demo',
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme:
|
colorScheme: ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 0, 67, 168)),
|
||||||
ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 255, 255, 255)),
|
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
),
|
),
|
||||||
home: MyHomePage(
|
home: const MyHomePage(title: 'COMUNIDAD DE REGANTES DE CIVÁN'),
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|||||||
152
lib/my_home_page.dart
Normal file
152
lib/my_home_page.dart
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
|
class MyHomePage extends StatelessWidget {
|
||||||
|
const MyHomePage({Key? key, required this.title}) : super(key: key);
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text(''),
|
||||||
|
centerTitle: true,
|
||||||
|
backgroundColor: Color.fromARGB(255, 194, 218, 230),
|
||||||
|
flexibleSpace: Container(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 30.0), // Margen superior
|
||||||
|
child: Image.asset(
|
||||||
|
'assets/logo-civan.png',
|
||||||
|
height: 150,
|
||||||
|
width: 150,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
|
||||||
|
body: Container(
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
image: DecorationImage(
|
||||||
|
image: AssetImage('assets/logo-fondo.png'),
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: <Widget>[
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
},
|
||||||
|
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: Color.fromARGB(255, 43, 102, 150),
|
||||||
|
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: () {
|
||||||
|
},
|
||||||
|
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: Color.fromARGB(255, 43, 102, 150),
|
||||||
|
borderRadius: BorderRadius.circular(7.0),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Pregón',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 32.0,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
},
|
||||||
|
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: Color.fromARGB(255, 43, 102, 150),
|
||||||
|
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: () {
|
||||||
|
},
|
||||||
|
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: Color.fromARGB(255, 43, 102, 150),
|
||||||
|
borderRadius: BorderRadius.circular(7.0),
|
||||||
|
),
|
||||||
|
child: const Text(
|
||||||
|
'Tiempo',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 32.0,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
pubspec.lock
32
pubspec.lock
@ -9,6 +9,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.11.0"
|
version: "2.11.0"
|
||||||
|
bloc:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: bloc
|
||||||
|
sha256: "6f1b87b6eca9041d5672b6e29273cd1594db48ebb66fd2471066e9f3c3a516bd"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "7.2.1"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -62,6 +70,14 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_bloc:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_bloc
|
||||||
|
sha256: cdd1351ced09eeb46cfa7946e095b7679344af927415ca9cd972928fa6d5b23f
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "7.3.3"
|
||||||
flutter_lints:
|
flutter_lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -136,6 +152,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.11.0"
|
version: "1.11.0"
|
||||||
|
nested:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: nested
|
||||||
|
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.0"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -152,6 +176,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.8"
|
version: "2.1.8"
|
||||||
|
provider:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: provider
|
||||||
|
sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "6.1.2"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|||||||
@ -31,6 +31,7 @@ dependencies:
|
|||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
url_launcher: ^6.0.12
|
url_launcher: ^6.0.12
|
||||||
|
flutter_bloc: ^7.0.0
|
||||||
|
|
||||||
|
|
||||||
# The following adds the Cupertino Icons font to your application.
|
# The following adds the Cupertino Icons font to your application.
|
||||||
@ -63,6 +64,7 @@ flutter:
|
|||||||
assets:
|
assets:
|
||||||
- assets/logo-civan.png
|
- assets/logo-civan.png
|
||||||
- assets/agua.jpg
|
- assets/agua.jpg
|
||||||
|
- assets/logo-fondo.png
|
||||||
# - images/a_dot_ham.jpeg
|
# - images/a_dot_ham.jpeg
|
||||||
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
# An image asset can refer to one or more resolution-specific "variants", see
|
||||||
|
|||||||
Reference in New Issue
Block a user