Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solucion Jaime Sanchez #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if (flutterVersionName == null) {
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 29
Expand All @@ -43,6 +44,7 @@ android {
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}

buildTypes {
Expand All @@ -60,4 +62,7 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.multidex:multidex:2.0.1'
implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.google.firebase:firebase-analytics'
}
39 changes: 39 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"project_info": {
"project_number": "849645478782",
"project_id": "flutter-in-the-dark-jsgala",
"storage_bucket": "flutter-in-the-dark-jsgala.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:849645478782:android:bc8821689b471fc3a1492f",
"android_client_info": {
"package_name": "com.example.chat_flutter_in_the_dark"
}
},
"oauth_client": [
{
"client_id": "849645478782-vbn2202q4j94ohpmol471qibg501guni.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAYpKjwyaehMyClwKCzIEE7O0qRLeUB4fo"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "849645478782-vbn2202q4j94ohpmol471qibg501guni.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.4'
}
}

Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
11 changes: 10 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import 'package:chat_flutter_in_the_dark/src/app/error_app.dart';
import 'package:chat_flutter_in_the_dark/src/app/loaded_app.dart';
import 'package:chat_flutter_in_the_dark/src/app/loading_app.dart';
import 'package:chat_flutter_in_the_dark/src/provider/chat_provider.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

void main() {
runApp(MyApp());
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => ChatState()),
],
child: MyApp(),
),
);
}

class MyApp extends StatelessWidget {
Expand Down
6 changes: 6 additions & 0 deletions lib/src/models/chat_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:flutter/foundation.dart';

class ChatModel extends ChangeNotifier{
String title;
String id;
}
5 changes: 5 additions & 0 deletions lib/src/models/message_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'package:flutter/foundation.dart';

class MessageModel extends ChangeNotifier{
String text;
}
24 changes: 14 additions & 10 deletions lib/src/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import 'package:chat_flutter_in_the_dark/src/bloc/chat/chat_bloc.dart';
import 'package:chat_flutter_in_the_dark/src/models/chat_model.dart';
import 'package:chat_flutter_in_the_dark/src/pages/chat.dart';
import 'package:chat_flutter_in_the_dark/src/provider/chat_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:provider/provider.dart';

class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('LISTADO DE CHATS'), backgroundColor: Colors.lime[800],),
body: BlocBuilder<ChatBloc, ChatState>(
builder: (context, state) {
if (state is FetchingChats) return Center(child: CircularProgressIndicator());
if (state is ErrorFetchingChats) return Center(child: Text('Error'));
if (state is FetchedChats)
body: Builder(
builder: (context) {
context.watch<ChatState>().fetchChats();
List<ChatModel> chats = context.watch<ChatState>().chats;
chatStates state = context.watch<ChatState>().state;
if (state == chatStates.fetching) return Center(child: CircularProgressIndicator());
if (state == chatStates.error) return Center(child: Text('Error'));
if (state == chatStates.fetched)
return ListView.builder(
itemCount: state.chats.length,
itemCount: chats.length,
itemBuilder: (context, index) => GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => ChatPage(chat: state.chats[index])),
MaterialPageRoute(builder: (context) => ChatPage(chat: chats[index])),
),
child: Container(
height: 100,
color: Colors.lime[300],
child: Center(
child:
Text(state.chats[index].title, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold))),
Text(chats[index].title, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold))),
),
),
);
Expand Down
15 changes: 15 additions & 0 deletions lib/src/provider/chat_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:chat_flutter_in_the_dark/src/models/chat_model.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';

enum chatStates { fetching, error, fetched }

class ChatState extends ChangeNotifier {
chatStates state = chatStates.fetching;
List<ChatModel> chats;

void fetchChats(){
FirebaseFirestore.instance.collection('chats').snapshots();
}

}
13 changes: 13 additions & 0 deletions lib/src/repositories/chat_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:chat_flutter_in_the_dark/src/models/message_model.dart';

class ChatRepository{
// Se cogen los mensajes del repositorio
Stream<List<MessageModel>> getMessages(String chatId){

}

// Se envian los mensajes al repositorio
void sendMessage(String chatId, String message){

}
}
16 changes: 15 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.3"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
path:
dependency: transitive
description:
Expand All @@ -177,6 +184,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
provider:
dependency: "direct main"
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "4.3.2+2"
quiver:
dependency: transitive
description:
Expand Down Expand Up @@ -247,4 +261,4 @@ packages:
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
flutter: ">=1.16.0 <2.0.0"
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
cupertino_icons: ^1.0.0
firebase_core: ^0.5.0
cloud_firestore: "^0.14.1+1"
provider: ^4.3.2+2

dev_dependencies:
flutter_test:
Expand Down