4Q-s-r-o / signature

Flutter plugin that creates a canvas for writing down a signature
MIT License
255 stars 85 forks source link

Bug report: Incorrect use of ParentDataWidget #49

Closed h7x4 closed 2 years ago

h7x4 commented 2 years ago

Consider the following example app:

main.dart ```dart import 'package:flutter/material.dart'; import 'package:signature/signature.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { final SignatureController controller = SignatureController(); @override Widget build(BuildContext context) { return MaterialApp( title: 'Signature Demo', home: Scaffold( appBar: AppBar(), body: Stack( children: [ Signature( controller: controller, backgroundColor: Colors.black12, ), IconButton( icon: Icon(Icons.delete), onPressed: () => controller.clear(), ) ], ), ), ); } } ```

When drawing, the console keeps spitting out this error message:

Another exception was thrown: Incorrect use of ParentDataWidget.

After looking a little bit around, I found that the causing line was the last part of the build function of SignatureState:

    if (widget.width != null || widget.height != null) {
      //IF DOUNDARIES ARE DEFINED, USE LIMITED BOX
      return Center(
        child: LimitedBox(
          maxWidth: maxWidth,
          maxHeight: maxHeight,
          child: signatureCanvas,
        ),
      );
    } else {
      //IF NO BOUNDARIES ARE DEFINED, USE EXPANDED
      return Expanded(child: signatureCanvas);
    }

Wrapping the canvas inside an Expanded widget only makes sense if the canvas is a child of Column, Row or Flex. See StackOverflow.

Although Expanded is needed when wrapped inside either of those three widgets, I think it would be better to let the user decide if the canvas should be expanded or not.

MartinHlavna commented 2 years ago

Released in 5.0.0