fluttercandies / flutter_drawing_board

A new Flutter package of drawing board
MIT License
178 stars 62 forks source link

lags and save feature not exist !? #10

Closed hixcoder closed 2 years ago

hixcoder commented 2 years ago

hello FlutterCandies team, I really love the package even if it not providing a way to custom the board, but it 's good with the default settings,

1- the first problem is that I can clearly see some lags when I draw a lot ! 2- the second problem , is the lack of the save button, when the user finish the draw, how they can save the draws?

hope you will update the package , bonus > you can add the feature of changing the board icons like the trash,pen.. icons!

thanks !

xSILENCEx commented 2 years ago
  1. Drawing a long line at a time will lead to drawing lag, this is a performance problem, there is no solution for the time being

  2. Use DrawingController to get drawing metadata

final DrawingController _drawingController = DrawingController();

DrawingBoard(
  controller: _drawingController,
  background: Container(width: 400, height: 400, color: Colors.white),
  showDefaultActions: true,
  showDefaultTools: true,
),

/// get drawing metadata
Future<void> _getImageData() async {
  print((await _drawingController.getImageData()).buffer.asInt8List());
}
  1. _drawingController.drawConfig is a ValueNotifier<DrawConfig?>, you can use ExValueBuilder<DrawConfig> to override each of the tools like this:
/// override pick color tool
ExValueBuilder<DrawConfig>(
    shouldRebuild: (DrawConfig? p, DrawConfig? n) => p?.color != n?.color,
    valueListenable: _drawingController.drawConfig,
    builder: (_, DrawConfig? dc, __) => TextButton(
        onPressed: _pickColor,
        style: TextButton.styleFrom(
            padding: EdgeInsets.zero,
            backgroundColor: dc?.color,
        ),
        child: const SizedBox.shrink(),
    ),
)
/// override a tools item
Widget _buildToolItem(IconData icon, PaintType type) {
  return ExValueBuilder<DrawConfig>(
    valueListenable: _drawingController.drawConfig,
    shouldRebuild: (DrawConfig? p, DrawConfig? n) => p?.paintType != n?.paintType,
    child: Icon(icon, color: Colors.blue, size: 20.w),
    builder: (_, DrawConfig? dc, Widget? c) => TextButton(
      style: TextButton.styleFrom(
        side: BorderSide(color: dc?.paintType == type ? Colors.blue : Colors.black12),
        padding: EdgeInsets.zero,
        backgroundColor: Colors.white,
        primary: Colors.blue,
      ),
      onPressed: () async {
        _drawingController.setType = type;
        if (type == PaintType.text) {
          // await _editText();
        }
      },
      child: c!,
    ),
  );
}
hixcoder commented 2 years ago

Thanks xSILENCEx , that was very good bro! I hope you will find a solution for the drawing lag issue 👍