Skip to content

use package:web for the grpc-web example #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions example/grpc-web/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.

import 'dart:async';
// ignore: deprecated_member_use (#756)
import 'dart:html';

import 'package:web/web.dart';

import 'src/generated/echo.pbgrpc.dart';

Expand Down Expand Up @@ -57,13 +57,14 @@ class EchoApp {
}

void _addMessage(String message, String cssClass) {
final classes = cssClass.split(' ');
querySelector('#first')!.after(DivElement()
..classes.add('row')
..append(Element.tag('h2')
..append(SpanElement()
..classes.add('label')
..classes.addAll(classes)
..text = message)));
final span = HTMLSpanElement()
..classList.add('label')
..text = message;
for (final classItem in cssClass.split(' ')) {
span.classList.add(classItem);
}
document.querySelector('#first')!.after(HTMLDivElement()
..classList.add('row')
..append(HTMLHeadingElement.h2()..append(span)));
}
}
1 change: 1 addition & 0 deletions example/grpc-web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies:
grpc:
path: ../../
protobuf: ^3.0.0
web: ^1.1.0

dev_dependencies:
build_runner: ^2.4.13
Expand Down
10 changes: 4 additions & 6 deletions example/grpc-web/web/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore: deprecated_member_use (#756)
import 'dart:html';

import 'package:grpc/grpc_web.dart';
import 'package:grpc_web/app.dart';
import 'package:grpc_web/src/generated/echo.pbgrpc.dart';
import 'package:web/web.dart';

void main() {
final channel = GrpcWebClientChannel.xhr(Uri.parse('http://localhost:8080'));
final service = EchoServiceClient(channel);
final app = EchoApp(service);

final button = querySelector('#send') as ButtonElement;
final button = document.querySelector('#send') as HTMLButtonElement;
button.onClick.listen((e) async {
final msg = querySelector('#msg') as TextInputElement;
final value = msg.value!.trim();
final msg = document.querySelector('#msg') as HTMLInputElement;
final value = msg.value.trim();
msg.value = '';

if (value.isEmpty) return;
Expand Down
8 changes: 3 additions & 5 deletions lib/src/shared/status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// ignore_for_file: prefer_relative_imports

import 'dart:convert';

import 'package:grpc/src/generated/google/protobuf/any.pb.dart';
import 'package:grpc/src/generated/google/rpc/error_details.pb.dart';
import 'package:grpc/src/generated/google/rpc/status.pb.dart';
import 'package:meta/meta.dart';
import 'package:protobuf/protobuf.dart';

import '../generated/google/protobuf/any.pb.dart';
import '../generated/google/rpc/error_details.pb.dart';
import '../generated/google/rpc/status.pb.dart';
import 'io_bits/io_bits.dart' show HttpStatus;

class StatusCode {
Expand Down
Loading