whiteboard_core 2.0.2-rc.0 copy "whiteboard_core: ^2.0.2-rc.0" to clipboard
whiteboard_core: ^2.0.2-rc.0 copied to clipboard

A Whiteboard Flutter package.

example/lib/main.dart

// Copyright (c) 2014-2020 NetEase, Inc.
// All right reserved.

import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_newebview/webview_flutter.dart';
import 'package:whiteboard_core/whiteboard_core.dart';

typedef WhiteBoardPageStatusCallback = void Function(bool isEditStatus);

class WhiteBoardWebPage extends StatefulWidget {
  final WhiteBoardPageStatusCallback whiteBoardPageStatusCallback;

  WhiteBoardWebPage({
    required this.whiteBoardPageStatusCallback,
  });

  @override
  _WhiteBoardWebPageState createState() {
    return _WhiteBoardWebPageState();
  }
}

class _WhiteBoardWebPageState extends State<WhiteBoardWebPage> {
  final _controller = Completer<WebViewController>();

  @override
  Widget build(BuildContext context) {
    return _buildBody();
  }

  Widget _buildBody() {
    return SafeArea(
      child: Stack(
        children: <Widget>[
          Positioned(
            child: Container(
              color: Colors.white,
              child: Center(
                child: WebView(
                  initialUrl: defaultWhiteBoardUrlG1,
                  scrollEnabled: false,
                  javascriptMode: JavascriptMode.unrestricted,
                  onWebViewCreated: (controller) {
                    print('onWebViewCreated ->');
                    assert(!_controller.isCompleted);
                    _controller.complete(controller);
                  },
                  onPageFinished: (url) {
                    print('onPageFinished url: ${url}');
                  },
                  javascriptChannels: <JavascriptChannel>{
                    NEWhiteBoard.instance.initWhiteboardJavascriptChannel(
                      _controller.future,
                      onWhiteboardPageLoaded: () {
                        /// You can call the login interface here,But you must use the information in the application, appKey
                        ///  NEWhiteBoard.instance.login();
                      },
                      onWhiteboardJoinWBSucceed: () => {
                        /// TODO Something
                      },
                      onWhiteboardInterceptLog: (log) {
                        ///  TODO Catch some error messages
                      },
                    )
                  },
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}