main.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import 'package:flutter/material.dart';
  2. import 'components/white_board/index.dart';
  3. import 'package:fis_common/event/event_type.dart';
  4. void main() {
  5. runApp(const MyApp());
  6. }
  7. class MyApp extends StatelessWidget {
  8. const MyApp({super.key});
  9. @override
  10. Widget build(BuildContext context) {
  11. return MaterialApp(
  12. title: '白板测试 Demo',
  13. theme: ThemeData(
  14. primarySwatch: Colors.blue,
  15. ),
  16. home: const WhiteBoardContainer(),
  17. );
  18. }
  19. }
  20. /// 白板容器,里面带有白板状态控制按钮及其状态
  21. class WhiteBoardContainer extends StatefulWidget {
  22. const WhiteBoardContainer({super.key});
  23. @override
  24. State<WhiteBoardContainer> createState() => _WhiteBoardContainerState();
  25. }
  26. class _WhiteBoardContainerState extends State<WhiteBoardContainer> {
  27. /// 当前用户 ID
  28. final currUserId = "123455";
  29. /// 当前绘制模式
  30. PaintType paintType = PaintType.curvedLine;
  31. /// 获取到数据事件通知
  32. FEventHandler<String> onReceiveDataHandler = FEventHandler<String>();
  33. /// 获取到清除事件通知
  34. FEventHandler<String> onClearCanavsHandler = FEventHandler<String>();
  35. @override
  36. Widget build(BuildContext context) {
  37. return Scaffold(
  38. appBar: AppBar(
  39. title: const Text('Flutter White Board Demo'),
  40. ),
  41. body: Center(
  42. child: Column(
  43. children: [
  44. /// 白板组件入口
  45. Expanded(
  46. child: WhiteBoard(
  47. userId: currUserId,
  48. paintType: paintType,
  49. sendData: (data) {
  50. debugPrint(data);
  51. },
  52. onReceiveData: onReceiveDataHandler,
  53. onClearCanavs: onClearCanavsHandler,
  54. ),
  55. ),
  56. _buildOperationButton(),
  57. ],
  58. ),
  59. ), // This trailing comma makes auto-formatting nicer for build methods.
  60. );
  61. }
  62. /// 操作按钮
  63. Widget _buildOperationButton() {
  64. return SizedBox(
  65. height: 50,
  66. child: Row(
  67. mainAxisAlignment: MainAxisAlignment.spaceAround,
  68. children: [
  69. TextButton(
  70. onPressed: () {
  71. setState(() {
  72. paintType = PaintType.straightLine;
  73. });
  74. },
  75. child: const Text(
  76. '直线',
  77. ),
  78. ),
  79. TextButton(
  80. onPressed: () {
  81. setState(() {
  82. paintType = PaintType.curvedLine;
  83. });
  84. },
  85. child: const Text(
  86. '曲线',
  87. ),
  88. ),
  89. TextButton(
  90. onPressed: () {
  91. onClearCanavsHandler.emit(this, currUserId);
  92. },
  93. child: const Text(
  94. '清除',
  95. ),
  96. ),
  97. ],
  98. ),
  99. );
  100. }
  101. }