import 'package:flutter/material.dart'; import 'components/white_board/index.dart'; import 'package:fis_common/event/event_type.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: '白板测试 Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const WhiteBoardContainer(), ); } } /// 白板容器,里面带有白板状态控制按钮及其状态 class WhiteBoardContainer extends StatefulWidget { const WhiteBoardContainer({super.key}); @override State createState() => _WhiteBoardContainerState(); } class _WhiteBoardContainerState extends State { /// 当前用户 ID final currUserId = "123455"; /// 当前绘制模式 PaintType paintType = PaintType.curvedLine; /// 获取到数据事件通知 FEventHandler onReceiveDataHandler = FEventHandler(); /// 获取到清除事件通知 FEventHandler onClearCanavsHandler = FEventHandler(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Flutter White Board Demo'), ), body: Center( child: Column( children: [ /// 白板组件入口 Expanded( child: WhiteBoard( userId: currUserId, paintType: paintType, sendData: (data) { debugPrint(data); }, onReceiveData: onReceiveDataHandler, onClearCanavs: onClearCanavsHandler, ), ), _buildOperationButton(), ], ), ), // This trailing comma makes auto-formatting nicer for build methods. ); } /// 操作按钮 Widget _buildOperationButton() { return SizedBox( height: 50, child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ TextButton( onPressed: () { setState(() { paintType = PaintType.straightLine; }); }, child: const Text( '直线', ), ), TextButton( onPressed: () { setState(() { paintType = PaintType.curvedLine; }); }, child: const Text( '曲线', ), ), TextButton( onPressed: () { onClearCanavsHandler.emit(this, currUserId); }, child: const Text( '清除', ), ), ], ), ); } }