123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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<WhiteBoardContainer> createState() => _WhiteBoardContainerState();
- }
- class _WhiteBoardContainerState extends State<WhiteBoardContainer> {
- /// 当前用户 ID
- final currUserId = "123455";
- /// 当前绘制模式
- PaintType paintType = PaintType.curvedLine;
- /// 获取到数据事件通知
- FEventHandler<String> onReceiveDataHandler = FEventHandler<String>();
- /// 获取到清除事件通知
- FEventHandler<String> onClearCanavsHandler = FEventHandler<String>();
- @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(
- '清除',
- ),
- ),
- ],
- ),
- );
- }
- }
|