From c1c0a2a492ba12265bf276c93e952b30932f3150 Mon Sep 17 00:00:00 2001 From: jaime-maverick Date: Thu, 3 Dec 2020 20:17:01 +0100 Subject: [PATCH 1/2] todo :( --- android/app/build.gradle | 5 +++ android/app/google-services.json | 39 +++++++++++++++++++++++ android/build.gradle | 1 + android/gradle.properties | 1 + lib/main.dart | 11 ++++++- lib/src/models/chat_model.dart | 6 ++++ lib/src/models/message_model.dart | 5 +++ lib/src/pages/home.dart | 24 ++++++++------ lib/src/provider/chat_provider.dart | 14 ++++++++ lib/src/repositories/chat_repository.dart | 13 ++++++++ pubspec.lock | 16 +++++++++- pubspec.yaml | 1 + 12 files changed, 124 insertions(+), 12 deletions(-) create mode 100644 android/app/google-services.json create mode 100644 lib/src/models/chat_model.dart create mode 100644 lib/src/models/message_model.dart create mode 100644 lib/src/provider/chat_provider.dart create mode 100644 lib/src/repositories/chat_repository.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 29636ca..ddd474b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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 @@ -43,6 +44,7 @@ android { targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName + multiDexEnabled true } buildTypes { @@ -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' } diff --git a/android/app/google-services.json b/android/app/google-services.json new file mode 100644 index 0000000..459fd22 --- /dev/null +++ b/android/app/google-services.json @@ -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" +} \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 3100ad2..9319192 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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' } } diff --git a/android/gradle.properties b/android/gradle.properties index 94adc3a..a673820 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,3 +1,4 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true +android.enableR8=true diff --git a/lib/main.dart b/lib/main.dart index 818e9d3..21f683f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 { diff --git a/lib/src/models/chat_model.dart b/lib/src/models/chat_model.dart new file mode 100644 index 0000000..ce01434 --- /dev/null +++ b/lib/src/models/chat_model.dart @@ -0,0 +1,6 @@ +import 'package:flutter/foundation.dart'; + +class ChatModel extends ChangeNotifier{ + String title; + String id; +} \ No newline at end of file diff --git a/lib/src/models/message_model.dart b/lib/src/models/message_model.dart new file mode 100644 index 0000000..0163868 --- /dev/null +++ b/lib/src/models/message_model.dart @@ -0,0 +1,5 @@ +import 'package:flutter/foundation.dart'; + +class MessageModel extends ChangeNotifier{ + String text; +} \ No newline at end of file diff --git a/lib/src/pages/home.dart b/lib/src/pages/home.dart index 3a74c9d..87c9625 100644 --- a/lib/src/pages/home.dart +++ b/lib/src/pages/home.dart @@ -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( - 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().fetchChats(); + List chats = context.watch().chats; + chatStates state = context.watch().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))), ), ), ); diff --git a/lib/src/provider/chat_provider.dart b/lib/src/provider/chat_provider.dart new file mode 100644 index 0000000..cebf9a2 --- /dev/null +++ b/lib/src/provider/chat_provider.dart @@ -0,0 +1,14 @@ +import 'package:chat_flutter_in_the_dark/src/models/chat_model.dart'; +import 'package:flutter/foundation.dart'; + +enum chatStates { fetching, error, fetched } + +class ChatState extends ChangeNotifier { + chatStates state = chatStates.fetching; + List chats; + + void fetchChats(){ + + } + +} diff --git a/lib/src/repositories/chat_repository.dart b/lib/src/repositories/chat_repository.dart new file mode 100644 index 0000000..61b72a7 --- /dev/null +++ b/lib/src/repositories/chat_repository.dart @@ -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> getMessages(String chatId){ + + } + + // Se envian los mensajes al repositorio + void sendMessage(String chatId, String message){ + + } +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 0800824..78a50e9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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: @@ -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: @@ -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" diff --git a/pubspec.yaml b/pubspec.yaml index f1787f7..a4d165d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: From bfb599071692e0a08cee5f93a2c1b14fa65ff9ee Mon Sep 17 00:00:00 2001 From: jaime-maverick Date: Thu, 3 Dec 2020 20:27:14 +0100 Subject: [PATCH 2/2] todo :( --- lib/src/provider/chat_provider.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/provider/chat_provider.dart b/lib/src/provider/chat_provider.dart index cebf9a2..44d772c 100644 --- a/lib/src/provider/chat_provider.dart +++ b/lib/src/provider/chat_provider.dart @@ -1,4 +1,5 @@ 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 } @@ -8,7 +9,7 @@ class ChatState extends ChangeNotifier { List chats; void fetchChats(){ - + FirebaseFirestore.instance.collection('chats').snapshots(); } }