Skip to content

Commit

Permalink
Merge pull request #3 from PauloniaAQP/firestore-update
Browse files Browse the repository at this point in the history
feat: Dependencies updated to run with Flutter 3.13
  • Loading branch information
ChrisChV authored Oct 11, 2023
2 parents 9f1ae45 + e1b00c7 commit 647da99
Show file tree
Hide file tree
Showing 13 changed files with 590 additions and 172 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [0.5.0]

- Dependencies updated to run with Flutter 3.13.
- `created` field removed from `PauloniaModel`.

## [0.4.0]

- Dependencies updated
Expand Down
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ app.*.symbols

# Obfuscation related
app.*.map.json
lib/firebase_options.dart
android/app/google-services.json
9 changes: 6 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ if (flutterVersionName == null) {
}

apply plugin: 'com.android.application'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 29
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -39,8 +42,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 29
minSdkVersion 19
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Generated file.
//
// If you wish to remove Flutter's multidex support, delete this entire file.
//
// Modifications to this file should be done in a copy under a different name
// as this file may be regenerated.

package io.flutter.app;

import android.app.Application;
import android.content.Context;
import androidx.annotation.CallSuper;
import androidx.multidex.MultiDex;

/**
* Extension of {@link android.app.Application}, adding multidex support.
*/
public class FlutterMultiDexApplication extends Application {
@Override
@CallSuper
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
9 changes: 6 additions & 3 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.8.21'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.4.2'
// START: FlutterFire Configuration
classpath 'com.google.gms:google-services:4.3.14'
// END: FlutterFire Configuration
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -26,6 +29,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip
71 changes: 62 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
import 'package:flutter/material.dart';
import 'package:paulonia_repository/PauloniaModel.dart';
import 'package:paulonia_repository/PauloniaRepository.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() {
class MyModel extends PauloniaModel<String> {

late String id;
late String value;
late Timestamp created;

MyModel(this.id, this.value, this.created);

}

class MyRepository extends PauloniaRepository<String, MyModel> {

CollectionReference? _collectionReference = FirebaseFirestore.instance.collection("test");

CollectionReference? get collectionReference => _collectionReference;

MyModel getFromDocSnap(DocumentSnapshot docSnap) {
return MyModel(
docSnap.id,
docSnap.get("value"),
docSnap.get('created'),
);
}

Future<List<MyModel>> getAll() async {
QuerySnapshot snapshot = await collectionReference!.get();
return getFromDocSnapList(snapshot.docs);
}
}


void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}

Expand Down Expand Up @@ -32,7 +72,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
Expand All @@ -52,6 +92,8 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

MyRepository repository = MyRepository();

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
Expand Down Expand Up @@ -97,13 +139,24 @@ class _MyHomePageState extends State<MyHomePage> {
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
FutureBuilder(future: repository.getAll(), builder: (context, snap) {
if (snap.hasData) {
if (snap.data == null) {
return const Text("null!!");
}
List<Widget> children = [];
for (MyModel model in snap.data! as List<MyModel>) {
children.add(Text(model.value));
}
return Column(
children: children,
);
}
if (snap.hasError) {
throw snap.error!;
}
return const Text("Loading");
}),
],
),
),
Expand Down
Loading

0 comments on commit 647da99

Please sign in to comment.