mirror of https://github.com/grpc/grpc-dart.git
use package:web for the grpc-web example
This commit is contained in:
parent
7f9042f79e
commit
a536c00a06
|
@ -14,8 +14,8 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
// ignore: deprecated_member_use (#756)
|
|
||||||
import 'dart:html';
|
import 'package:web/web.dart';
|
||||||
|
|
||||||
import 'src/generated/echo.pbgrpc.dart';
|
import 'src/generated/echo.pbgrpc.dart';
|
||||||
|
|
||||||
|
@ -57,13 +57,14 @@ class EchoApp {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addMessage(String message, String cssClass) {
|
void _addMessage(String message, String cssClass) {
|
||||||
final classes = cssClass.split(' ');
|
final span = HTMLSpanElement()
|
||||||
querySelector('#first')!.after(DivElement()
|
..classList.add('label')
|
||||||
..classes.add('row')
|
..text = message;
|
||||||
..append(Element.tag('h2')
|
for (final classItem in cssClass.split(' ')) {
|
||||||
..append(SpanElement()
|
span.classList.add(classItem);
|
||||||
..classes.add('label')
|
}
|
||||||
..classes.addAll(classes)
|
document.querySelector('#first')!.after(HTMLDivElement()
|
||||||
..text = message)));
|
..classList.add('row')
|
||||||
|
..append(HTMLHeadingElement.h2()..append(span)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ dependencies:
|
||||||
grpc:
|
grpc:
|
||||||
path: ../../
|
path: ../../
|
||||||
protobuf: ^3.0.0
|
protobuf: ^3.0.0
|
||||||
|
web: ^1.1.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.4.13
|
build_runner: ^2.4.13
|
||||||
|
|
|
@ -13,22 +13,20 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// ignore: deprecated_member_use (#756)
|
|
||||||
import 'dart:html';
|
|
||||||
|
|
||||||
import 'package:grpc/grpc_web.dart';
|
import 'package:grpc/grpc_web.dart';
|
||||||
import 'package:grpc_web/app.dart';
|
import 'package:grpc_web/app.dart';
|
||||||
import 'package:grpc_web/src/generated/echo.pbgrpc.dart';
|
import 'package:grpc_web/src/generated/echo.pbgrpc.dart';
|
||||||
|
import 'package:web/web.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
final channel = GrpcWebClientChannel.xhr(Uri.parse('http://localhost:8080'));
|
final channel = GrpcWebClientChannel.xhr(Uri.parse('http://localhost:8080'));
|
||||||
final service = EchoServiceClient(channel);
|
final service = EchoServiceClient(channel);
|
||||||
final app = EchoApp(service);
|
final app = EchoApp(service);
|
||||||
|
|
||||||
final button = querySelector('#send') as ButtonElement;
|
final button = document.querySelector('#send') as HTMLButtonElement;
|
||||||
button.onClick.listen((e) async {
|
button.onClick.listen((e) async {
|
||||||
final msg = querySelector('#msg') as TextInputElement;
|
final msg = document.querySelector('#msg') as HTMLInputElement;
|
||||||
final value = msg.value!.trim();
|
final value = msg.value.trim();
|
||||||
msg.value = '';
|
msg.value = '';
|
||||||
|
|
||||||
if (value.isEmpty) return;
|
if (value.isEmpty) return;
|
||||||
|
|
|
@ -13,16 +13,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// ignore_for_file: prefer_relative_imports
|
|
||||||
|
|
||||||
import 'dart:convert';
|
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:meta/meta.dart';
|
||||||
import 'package:protobuf/protobuf.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;
|
import 'io_bits/io_bits.dart' show HttpStatus;
|
||||||
|
|
||||||
class StatusCode {
|
class StatusCode {
|
||||||
|
|
Loading…
Reference in New Issue