Skip to content

Commit

Permalink
refactor(*): migrate remaining examples & e2e tests to null-safety (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pr-Mais committed Nov 25, 2021
1 parent e00c36e commit 0ca85e5
Show file tree
Hide file tree
Showing 75 changed files with 1,088 additions and 1,620 deletions.
Expand Up @@ -25,6 +25,6 @@
<string>arm64</string>
</array>
<key>MinimumOSVersion</key>
<string>8.0</string>
<string>9.0</string>
</dict>
</plist>
@@ -0,0 +1,45 @@
import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';

class DefaultFirebaseConfig {
static FirebaseOptions get platformOptions {
if (kIsWeb) {
// Web
return const FirebaseOptions(
apiKey: 'AIzaSyAgUhHU8wSJgO5MVNy95tMT07NEjzMOfz0',
authDomain: 'react-native-firebase-testing.firebaseapp.com',
databaseURL: 'https://react-native-firebase-testing.firebaseio.com',
projectId: 'react-native-firebase-testing',
storageBucket: 'react-native-firebase-testing.appspot.com',
messagingSenderId: '448618578101',
appId: '1:448618578101:web:772d484dc9eb15e9ac3efc',
measurementId: 'G-0N1G9FLDZE',
);
} else if (Platform.isIOS || Platform.isMacOS) {
// iOS and MacOS
return const FirebaseOptions(
appId: '1:448618578101:ios:2bc5c1fe2ec336f8ac3efc',
apiKey: 'AIzaSyAHAsf51D0A407EklG1bs-5wA7EbyfNFg0',
projectId: 'react-native-firebase-testing',
messagingSenderId: '448618578101',
iosBundleId: 'io.flutter.plugins.firebase.firestore.example',
iosClientId:
'448618578101-ja1be10uicsa2dvss16gh4hkqks0vq61.apps.googleusercontent.com',
androidClientId:
'448618578101-2baveavh8bvs2famsa5r8t77fe1nrcn6.apps.googleusercontent.com',
storageBucket: 'react-native-firebase-testing.appspot.com',
databaseURL: 'https://react-native-firebase-testing.firebaseio.com',
);
} else {
// Android
return const FirebaseOptions(
appId: '1:448618578101:android:3ad281c0067ccf97ac3efc',
apiKey: 'AIzaSyCuu4tbv9CwwTudNOweMNstzZHIDBhgJxA',
projectId: 'react-native-firebase-testing',
messagingSenderId: '448618578101',
);
}
}
}
18 changes: 6 additions & 12 deletions packages/cloud_firestore/cloud_firestore/example/lib/main.dart
Expand Up @@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:cloud_firestore_example/firebase_config.dart';
import 'package:cloud_firestore_example/movie.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
Expand All @@ -13,14 +14,7 @@ bool USE_FIRESTORE_EMULATOR = false;

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: const FirebaseOptions(
apiKey: 'AIzaSyAHAsf51D0A407EklG1bs-5wA7EbyfNFg0',
appId: '1:448618578101:ios:2bc5c1fe2ec336f8ac3efc',
messagingSenderId: '448618578101',
projectId: 'react-native-firebase-testing',
),
);
await Firebase.initializeApp(options: DefaultFirebaseConfig.platformOptions);

if (USE_FIRESTORE_EMULATOR) {
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
Expand Down Expand Up @@ -218,9 +212,7 @@ class _MovieItem extends StatelessWidget {
Widget get poster {
return SizedBox(
width: 100,
child: Center(
child: Image.network(movie.poster),
),
child: Image.network(movie.poster),
);
}

Expand Down Expand Up @@ -255,7 +247,8 @@ class _MovieItem extends StatelessWidget {
Widget get metadata {
return Padding(
padding: const EdgeInsets.only(top: 8),
child: Row(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(right: 8),
Expand Down Expand Up @@ -299,6 +292,7 @@ class _MovieItem extends StatelessWidget {
return Padding(
padding: const EdgeInsets.only(bottom: 4, top: 4),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
poster,
Flexible(child: details),
Expand Down
Expand Up @@ -26,12 +26,8 @@
33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; };
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; };
33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; };
33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; };
33D1A10522148B93006C7A3E /* FlutterMacOS.framework in Bundle Framework */ = {isa = PBXBuildFile; fileRef = 33D1A10322148B71006C7A3E /* FlutterMacOS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
B550B1FA23F53055007DADD5 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = B550B1F923F53055007DADD5 /* GoogleService-Info.plist */; };
CF00B2C1BAC6C45C8CEC0ABB /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 20AC44AD05DF01F5CE774C68 /* Pods_Runner.framework */; };
D73912F022F37F9E000D13A0 /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D73912EF22F37F9E000D13A0 /* App.framework */; };
D73912F222F3801D000D13A0 /* App.framework in Bundle Framework */ = {isa = PBXBuildFile; fileRef = D73912EF22F37F9E000D13A0 /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -51,8 +47,6 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
D73912F222F3801D000D13A0 /* App.framework in Bundle Framework */,
33D1A10522148B93006C7A3E /* FlutterMacOS.framework in Bundle Framework */,
);
name = "Bundle Framework";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -72,7 +66,6 @@
33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = "<group>"; };
33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = "<group>"; };
33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = "<group>"; };
33D1A10322148B71006C7A3E /* FlutterMacOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FlutterMacOS.framework; path = Flutter/ephemeral/FlutterMacOS.framework; sourceTree = SOURCE_ROOT; };
33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = "<group>"; };
33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = "<group>"; };
33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = "<group>"; };
Expand All @@ -81,7 +74,6 @@
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
B550B1F923F53055007DADD5 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
BFF2C4019A4A6B2204D78167 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
D73912EF22F37F9E000D13A0 /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/ephemeral/App.framework; sourceTree = SOURCE_ROOT; };
F84572E2CE6BA0CFCE7EC16B /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -90,8 +82,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
D73912F022F37F9E000D13A0 /* App.framework in Frameworks */,
33D1A10422148B71006C7A3E /* FlutterMacOS.framework in Frameworks */,
CF00B2C1BAC6C45C8CEC0ABB /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -147,8 +137,6 @@
33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */,
33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */,
33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */,
D73912EF22F37F9E000D13A0 /* App.framework */,
33D1A10322148B71006C7A3E /* FlutterMacOS.framework */,
);
path = Flutter;
sourceTree = "<group>";
Expand Down Expand Up @@ -199,6 +187,7 @@
33CC110E2044A8840003C045 /* Bundle Framework */,
3399D490228B24CF009A79C7 /* ShellScript */,
975391D0C03E32306137DE4C /* [CP] Embed Pods Frameworks */,
BAB8F2C5684814BE2193F3E5 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -306,7 +295,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename\n";
shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n";
};
33CC111E2044C6BF0003C045 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
Expand All @@ -333,16 +322,31 @@
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
BAB8F2C5684814BE2193F3E5 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down
6 changes: 3 additions & 3 deletions packages/cloud_firestore/cloud_firestore/example/pubspec.yaml
Expand Up @@ -2,8 +2,8 @@ name: cloud_firestore_example
description: Demonstrates how to use the firestore plugin.

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.12.13+hotfix.4"
sdk: '>=2.12.0 <3.0.0'
flutter: '>=1.12.13+hotfix.4'

dependencies:
cloud_firestore:
Expand All @@ -27,7 +27,7 @@ dependency_overrides:
path: ../../../firebase_core/firebase_core_web

dev_dependencies:
drive: ^0.1.0
drive: ^1.0.0-1.0.nullsafety.1
flutter_driver:
sdk: flutter
test: any
Expand Down
@@ -1,4 +1,3 @@
// @dart=2.9
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Expand All @@ -12,6 +11,7 @@ import 'collection_reference_e2e.dart';
import 'document_change_e2e.dart';
import 'document_reference_e2e.dart';
import 'field_value_e2e.dart';
import 'firebase_config.dart';
import 'geo_point_e2e.dart';
import 'instance_e2e.dart';
import 'query_e2e.dart';
Expand All @@ -25,7 +25,7 @@ bool kUseFirestoreEmulator = true;

void testsMain() {
setUpAll(() async {
await Firebase.initializeApp();
await Firebase.initializeApp(options: TestFirebaseConfig.platformOptions);

if (kUseFirestoreEmulator) {
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
Expand Down
@@ -1,4 +1,3 @@
// @dart=2.9
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Expand Down
Expand Up @@ -2,16 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart=2.9

import 'dart:async';

import 'package:flutter_test/flutter_test.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

void runFieldValueTests() {
group('$FieldValue', () {
FirebaseFirestore /*?*/ firestore;
late FirebaseFirestore firestore;

setUpAll(() async {
firestore = FirebaseFirestore.instance;
Expand All @@ -32,7 +30,7 @@ void runFieldValueTests() {
await doc.set({'foo': 2});
await doc.update({'foo': FieldValue.increment(1)});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals(3));
expect(snapshot.data()!['foo'], equals(3));
});

test('decrements a number', () async {
Expand All @@ -41,7 +39,7 @@ void runFieldValueTests() {
await doc.set({'foo': 2});
await doc.update({'foo': FieldValue.increment(-1)});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals(1));
expect(snapshot.data()!['foo'], equals(1));
});

test('sets an increment if it does not exist', () async {
Expand All @@ -51,7 +49,7 @@ void runFieldValueTests() {
expect(snapshot.exists, isFalse);
await doc.set({'foo': FieldValue.increment(1)});
DocumentSnapshot<Map<String, dynamic>> snapshot2 = await doc.get();
expect(snapshot2.data()['foo'], equals(1));
expect(snapshot2.data()!['foo'], equals(1));
});
});

Expand All @@ -61,20 +59,20 @@ void runFieldValueTests() {
await initializeTest('field-value-server-timestamp-new');
await doc.set({'foo': FieldValue.serverTimestamp()});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], isA<Timestamp>());
expect(snapshot.data()!['foo'], isA<Timestamp>());
});

test('updates a server time value', () async {
DocumentReference<Map<String, dynamic>> doc =
await initializeTest('field-value-server-timestamp-update');
await doc.set({'foo': FieldValue.serverTimestamp()});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
Timestamp serverTime1 = snapshot.data()['foo'];
Timestamp serverTime1 = snapshot.data()!['foo'];
expect(serverTime1, isA<Timestamp>());
await Future.delayed(const Duration(milliseconds: 100));
await doc.update({'foo': FieldValue.serverTimestamp()});
DocumentSnapshot<Map<String, dynamic>> snapshot2 = await doc.get();
Timestamp serverTime2 = snapshot2.data()['foo'];
Timestamp serverTime2 = snapshot2.data()!['foo'];
expect(serverTime2, isA<Timestamp>());
expect(
serverTime2.microsecondsSinceEpoch >
Expand Down Expand Up @@ -106,7 +104,7 @@ void runFieldValueTests() {
'foo': FieldValue.arrayUnion([3, 4])
});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals([1, 2, 3, 4]));
expect(snapshot.data()!['foo'], equals([1, 2, 3, 4]));
});

test('updates an array if current value is not an array', () async {
Expand All @@ -117,7 +115,7 @@ void runFieldValueTests() {
'foo': FieldValue.arrayUnion([3, 4])
});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals([3, 4]));
expect(snapshot.data()!['foo'], equals([3, 4]));
});

test('sets an array if current value is not an array', () async {
Expand All @@ -128,7 +126,7 @@ void runFieldValueTests() {
'foo': FieldValue.arrayUnion([3, 4])
});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals([3, 4]));
expect(snapshot.data()!['foo'], equals([3, 4]));
});
});

Expand All @@ -143,7 +141,7 @@ void runFieldValueTests() {
'foo': FieldValue.arrayRemove([3, 4])
});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals([1, 2]));
expect(snapshot.data()!['foo'], equals([1, 2]));
});

test('removes & updates an array if existing item is not an array',
Expand All @@ -155,7 +153,7 @@ void runFieldValueTests() {
'foo': FieldValue.arrayUnion([3, 4])
});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals([3, 4]));
expect(snapshot.data()!['foo'], equals([3, 4]));
});

test('removes & sets an array if existing item is not an array',
Expand All @@ -167,7 +165,7 @@ void runFieldValueTests() {
'foo': FieldValue.arrayUnion([3, 4])
});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals([3, 4]));
expect(snapshot.data()!['foo'], equals([3, 4]));
});

// ignore: todo
Expand All @@ -188,7 +186,7 @@ void runFieldValueTests() {
'foo': FieldValue.arrayUnion([2, ref])
});
DocumentSnapshot<Map<String, dynamic>> snapshot = await doc.get();
expect(snapshot.data()['foo'], equals([1, 2, ref]));
expect(snapshot.data()!['foo'], equals([1, 2, ref]));
},
skip: true,
);
Expand Down

0 comments on commit 0ca85e5

Please sign in to comment.