Skip to content

Commit 28f258e

Browse files
Merge pull request appwrite#607 from appwrite/fix-flutter-test
2 parents 3a0b829 + 1042b44 commit 28f258e

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ env:
2929
- SDK=DartStable
3030
- SDK=Deno1171
3131
- SDK=FlutterStable
32+
- SDK=FlutterBeta
3233
- SDK=Go112
3334
- SDK=Go118
34-
# - SDK=FlutterBeta
3535
- SDK=KotlinJava8
3636
- SDK=KotlinJava11
3737
- SDK=KotlinJava17

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,18 @@ class ClientIO extends ClientBase with ClientMixin {
133133
Future init() async {
134134
if(_initProgress) return;
135135
_initProgress = true;
136-
// if web skip cookie implementation and origin header as those are automatically handled by browsers
137136
final Directory cookieDir = await _getCookiePath();
138137
_cookieJar = PersistCookieJar(storage: FileStorage(cookieDir.path));
139138
_interceptors.add(CookieManager(_cookieJar));
140-
PackageInfo packageInfo = await PackageInfo.fromPlatform();
141-
addHeader('Origin',
142-
'appwrite-${Platform.operatingSystem}://${packageInfo.packageName}');
143139

144-
//creating custom user agent
145-
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
146140
var device = '';
147141
try {
142+
PackageInfo packageInfo = await PackageInfo.fromPlatform();
143+
addHeader('Origin',
144+
'appwrite-${Platform.operatingSystem}://${packageInfo.packageName}');
145+
146+
//creating custom user agent
147+
DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();
148148
if (Platform.isAndroid) {
149149
final andinfo = await deviceInfoPlugin.androidInfo;
150150
device =
@@ -167,12 +167,14 @@ class ClientIO extends ClientBase with ClientMixin {
167167
final macinfo = await deviceInfoPlugin.macOsInfo;
168168
device = '(Macintosh; ${macinfo.model})';
169169
}
170+
addHeader(
171+
'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');
170172
} catch (e) {
171173
debugPrint('Error getting device info: $e');
172174
device = Platform.operatingSystem;
175+
addHeader(
176+
'user-agent', '$device');
173177
}
174-
addHeader(
175-
'user-agent', '${packageInfo.packageName}/${packageInfo.version} $device');
176178

177179
_initialized = true;
178180
_initProgress = false;

templates/flutter/lib/src/cookie_manager.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class CookieManager extends Interceptor {
2323
}
2424
return request;
2525
}).catchError((e, stackTrace) {
26-
// throw AppwriteException(e.message);
26+
return request;
2727
});
2828
return request;
2929
}
3030

3131
@override
3232
FutureOr<http.Response> onResponse(http.Response response) {
3333
_saveCookies(response).then((_) => response).catchError((e, stackTrace) {
34-
// throw AppwriteException(e.message);
34+
return response;
3535
});
3636
return response;
3737
}

templates/flutter/pubspec.yaml.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ dependencies:
1616
flutter_web_auth_2: ^2.0.2
1717
http: ^0.13.5
1818
package_info_plus: ^3.0.2
19-
path_provider: ^2.0.11
19+
path_provider: ^2.0.12
2020
web_socket_channel: ^2.2.0
2121
universal_html: ^2.0.8
2222
2323
dev_dependencies:
24+
path_provider_platform_interface: ^2.0.5
2425
flutter_lints: ^2.0.1
2526
flutter_test:
2627
sdk: flutter

tests/languages/flutter/tests.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import 'package:flutter/material.dart';
2+
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
3+
24
import '../lib/packageName.dart';
5+
import '../lib/client_io.dart';
36
import '../lib/models.dart';
7+
import 'dart:io';
8+
9+
class FakePathProvider extends PathProviderPlatform {
10+
@override
11+
Future<String?> getApplicationDocumentsPath() async {
12+
return '.';
13+
}
14+
}
15+
416

517
void main() async {
618
WidgetsFlutterBinding.ensureInitialized();
19+
PathProviderPlatform.instance = FakePathProvider();
720
Client client = Client();
821
Foo foo = Foo(client);
922
Bar bar = Bar(client);

0 commit comments

Comments
 (0)