File tree 3 files changed +23
-14
lines changed
3 files changed +23
-14
lines changed Original file line number Diff line number Diff line change 14
14
// limitations under the License.
15
15
16
16
import 'dart:async' ;
17
- import 'dart:html' ;
18
-
17
+ import 'package:web/web.dart' ;
19
18
import 'src/generated/echo.pbgrpc.dart' ;
20
19
21
20
class EchoApp {
@@ -56,13 +55,23 @@ class EchoApp {
56
55
}
57
56
58
57
void _addMessage (String message, String cssClass) {
59
- final classes = cssClass.split (' ' );
60
- querySelector ('#first' )! .after (DivElement ()
61
- ..classes.add ('row' )
62
- ..append (Element .tag ('h2' )
63
- ..append (SpanElement ()
64
- ..classes.add ('label' )
65
- ..classes.addAll (classes)
58
+ document.querySelector ('#first' )! .after (HTMLDivElement ()
59
+ ..classList.add ('row' )
60
+ ..append (HTMLHeadingElement .h2 ()
61
+ ..append (HTMLSpanElement ()
62
+ ..classList.add ('label' )
63
+ ..classList.addAll (cssClass)
66
64
..text = message)));
67
65
}
68
66
}
67
+
68
+ // The documentation of DOMTokenList.add implies it can handle multiple classes,
69
+ // but in Chrome at least it does not.
70
+ extension AddAll on DOMTokenList {
71
+ void addAll (String cssClass) {
72
+ final classes = cssClass.split (' ' );
73
+ for (final c in classes) {
74
+ add (c);
75
+ }
76
+ }
77
+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ dependencies:
9
9
grpc :
10
10
path : ../../
11
11
protobuf : ^3.0.0
12
+ web : ^1.1.0
12
13
13
14
dev_dependencies :
14
15
build_runner : ^2.0.0
Original file line number Diff line number Diff line change 12
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
// See the License for the specific language governing permissions and
14
14
// limitations under the License.
15
- import 'dart:html' ;
16
-
17
15
import 'package:grpc/grpc_web.dart' ;
18
16
import 'package:grpc_web/app.dart' ;
19
17
import 'package:grpc_web/src/generated/echo.pbgrpc.dart' ;
18
+ import 'package:web/web.dart' ;
20
19
21
20
void main () {
22
21
final channel = GrpcWebClientChannel .xhr (Uri .parse ('http://localhost:8080' ));
23
22
final service = EchoServiceClient (channel);
24
23
final app = EchoApp (service);
25
24
26
- final button = querySelector ('#send' ) as ButtonElement ;
25
+ final button = document. querySelector ('#send' ) as HTMLButtonElement ;
27
26
button.onClick.listen ((e) async {
28
- final msg = querySelector ('#msg' ) as TextInputElement ;
29
- final value = msg.value! .trim ();
27
+ final msg = document. querySelector ('#msg' ) as HTMLInputElement ;
28
+ final value = msg.value.trim ();
30
29
msg.value = '' ;
31
30
32
31
if (value.isEmpty) return ;
You can’t perform that action at this time.
0 commit comments