Skip to content

Commit 8c51baf

Browse files
committed
Revert back to servicestack/client.dart and remove flutter deps
1 parent 1e80d0e commit 8c51baf

21 files changed

+34
-684
lines changed

README.md

Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,6 @@ The `JsonServiceClient` is a smart full-featured Service Client implementation w
116116

117117
Behind the scenes `JsonServiceClient` leverages the optimal [`HttpClient` in dart:io](https://docs.flutter.io/flutter/dart-io/HttpClient-class.html) to perform HTTP Requests in Flutter and Dart VM Apps.
118118

119-
### JsonWebClient
120-
121-
The `servicestack` Dart package also includes an alternative `JsonWebClient` implementation which instead performs HTTP Requests using [dart:html BrowserClient](https://webdev.dartlang.org/angular/guide/server-communication) to use the browsers built-in `XMLHttpRequest` object. Despite their implementation differences `JsonWebClient` also supports the same feature-set as the Dart VM's `JsonServiceClient` above.
122-
123-
AngularDart or Dart Web Apps can use `JsonWebClient` by importing `web.dart`, e.g:
124-
125-
```dart
126-
import 'package:servicestack/servicestack.dart';
127-
import 'package:servicestack/web.dart';
128-
129-
var client = new JsonWebClient("https://www.techstacks.io");
130-
```
131-
132119
### IServiceClient API
133120

134121
Both JSON Service Client variants implement the same flexible `IServiceClient` API below, use the same DTOs and implementation and throws the same structured `WebServiceException` which results in Typed API Requests being source-compatible between Dart Web Apps, Dart VM Server and AOT compiled Flutter Web Apps:
@@ -195,9 +182,7 @@ This creates a basic Flutter App which you can run in your Android Device or And
195182
Then to use `JsonServiceClient` add the `servicestack` dependency to your apps [pubspec.yaml](https://github.com/ServiceStackApps/HelloFlutter/blob/master/pubspec.yaml):
196183

197184
dependencies:
198-
flutter:
199-
sdk: flutter
200-
servicestack: "^1.0.0"
185+
servicestack: "^1.0.2"
201186

202187
Saving `pubspec.yaml` automatically runs [flutter packages get](https://flutter.io/using-packages/) to install any new dependencies in your App.
203188

@@ -480,128 +465,6 @@ To display the image we assign the response to the `imageBytes` field within the
480465

481466
![](https://raw.githubusercontent.com/ServiceStack/docs/master/docs/images/dart/flutter/helloflutter-06.png)
482467

483-
### Angular Dart
484-
485-
The [HelloAngularDart](https://github.com/ServiceStackApps/HelloAngularDart) project demonstrates the same functionality in an AngularDart Web App running inside a Web Browser.
486-
487-
The only difference is having to also import `web.dart` containing the `JsonWebClient`:
488-
489-
```dart
490-
import 'package:servicestack/web.dart';
491-
```
492-
493-
and changing the clients to use the `JsonWebClient` instead, e.g:
494-
495-
```dart
496-
var testClient = new JsonWebClient(TestBaseUrl);
497-
var techstacksClient = new JsonWebClient(TechStacksBaseUrl);
498-
```
499-
500-
But otherwise the actual client source code for all of the Typed API requests remains exactly the same.
501-
502-
The `HelloAngularDart` App is contained within the [hello_world](https://github.com/ServiceStackApps/HelloAngularDart/tree/master/lib/src/hello_world) component with all Dart logic in:
503-
504-
#### [hello_world.dart](https://github.com/ServiceStackApps/HelloAngularDart/blob/master/lib/src/hello_world/hello_world.dart)
505-
506-
```dart
507-
import 'dart:typed_data';
508-
import 'dart:convert';
509-
510-
import 'package:angular/angular.dart';
511-
import 'package:servicestack/servicestack.dart';
512-
import 'package:servicestack/web.dart';
513-
514-
import '../dtos/test.dtos.dart';
515-
import '../dtos/techstacks.dtos.dart';
516-
517-
@Component(
518-
selector: 'hello-world',
519-
styleUrls: const ['hello_world.css'],
520-
templateUrl: 'hello_world.html',
521-
)
522-
class HelloWorldComponent {
523-
var result = "";
524-
var imageSrc = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="; // 1x1 pixel
525-
static const TestBaseUrl = "http://test.servicestack.net";
526-
static const TechStacksBaseUrl = "https://www.techstacks.io";
527-
var testClient = new JsonWebClient(TestBaseUrl);
528-
var techstacksClient = new JsonWebClient(TechStacksBaseUrl);
529-
530-
doAsync() async {
531-
var r = await testClient.get(new Hello(name: "Async"));
532-
result = r.result;
533-
}
534-
535-
doAuth() async {
536-
var auth = await testClient.post(new Authenticate(
537-
provider: "credentials", userName: "test", password: "test"));
538-
var r = await testClient.get(new HelloAuth(name: "Auth"));
539-
result = "${r.result} your JWT is: ${auth.bearerToken}";
540-
}
541-
542-
doJWT() async {
543-
var auth = await testClient.post(new Authenticate(
544-
provider: "credentials", userName: "test", password: "test"));
545-
546-
var newClient = new JsonWebClient(TestBaseUrl)
547-
..refreshToken = auth.refreshToken;
548-
var r = await newClient.get(new HelloAuth(name: "JWT"));
549-
result = "${r.result} your RefreshToken is: ${auth.refreshToken}";
550-
}
551-
552-
doQuery() async {
553-
var techs = await techstacksClient
554-
.get(new FindTechnologies(), args: {"slug": "flutter"});
555-
var posts = await techstacksClient.get(new QueryPosts(
556-
anyTechnologyIds: [techs.results[0].id],
557-
types: ['Announcement', 'Showcase'])
558-
..take = 1);
559-
result = "Latest Flutter Announcement:\n“${posts.results[0].title}”";
560-
}
561-
562-
doBatch() async {
563-
var requests = ['foo', 'bar', 'qux'].map((name) => new Hello(name: name));
564-
var responses = await testClient.sendAll(requests);
565-
result = "Batch Responses:\n${responses.map((r) => r.result).join('\n')}";
566-
}
567-
568-
doImage() async {
569-
Uint8List bytes = await testClient.get(new HelloImage(
570-
name: "Flutter",
571-
fontFamily: "Roboto",
572-
background: "#0091EA",
573-
width: 500,
574-
height: 170));
575-
576-
result = "";
577-
imageSrc = "data:image/png;base64," + base64.encode(bytes);
578-
}
579-
}
580-
```
581-
582-
#### [hello_world.html](https://github.com/ServiceStackApps/HelloAngularDart/blob/master/lib/src/hello_world/hello_world.html)
583-
584-
Which uses this template markup to render its UI:
585-
586-
```html
587-
<div>
588-
<button (click)="doAsync()">Async</button>
589-
<button (click)="doAuth()">Auth</button>
590-
<button (click)="doJWT()">JWT</button>
591-
<button (click)="doQuery()">Query</button>
592-
<button (click)="doBatch()">Batch</button>
593-
<button (click)="doImage()">Image</button>
594-
</div>
595-
596-
<div id="result">{{result}}</div>
597-
598-
<img src="{{imageSrc}}">
599-
```
600-
601-
Where it runs a functionally equivalent App in a browser:
602-
603-
![](https://raw.githubusercontent.com/ServiceStack/docs/master/docs/images/dart/angulardart/helloangulardart-01.png)
604-
605468

606469
## DTO Customization Options
607470

lib/client.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
library client;
2+
3+
import 'dart:io';
4+
import 'dart:async';
5+
import 'dart:convert';
6+
import 'dart:typed_data';
7+
8+
part 'interfaces.dart';
9+
part 'client_dtos.dart';
10+
part 'utils.dart';
11+
part 'json_converters.dart';
12+
part 'converters/duration_converter.dart';
13+
part 'json_service_client.dart';

lib/client_dtos.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of servicestack;
1+
part of client;
22

33
abstract class IReturn<T>
44
{

lib/converters/duration_converter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of servicestack;
1+
part of client;
22

33
class DurationConverter implements IConverter
44
{

lib/interfaces.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of servicestack;
1+
part of client;
22

33
abstract class IConverter
44
{

lib/json_converters.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of servicestack;
1+
part of client;
22

33
class JsonConverters
44
{

lib/json_service_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of servicestack;
1+
part of client;
22

33
typedef void UrlFilter(String url);
44
typedef Future AsyncCallbackFunction();

lib/servicestack.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
library servicestack;
1+
library client;
22

33
import 'dart:io';
44
import 'dart:async';

lib/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
part of servicestack;
1+
part of client;
22

33
List<String> splitOnFirst(String s, String c) {
44
if (s == null || s == "") return [s];

0 commit comments

Comments
 (0)