diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9b5962..445286fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.1.0] + +* Update internal dependencies +* Update minimum Dart version to 2.0 +* Update minimum Flutter version to 3.16 + ## [1.0.1] * Fix a bug where `TextDrawable`s would incorrectly render on the final image ([Issue #19](https://github.com/omarhurani/flutter_painter/issues/19)). * Add Flutter linting using [flutter_lints](https://pub.dev/packages/flutter_lints) ([Issue #20](https://github.com/omarhurani/flutter_painter/issues/20)). diff --git a/analysis_options.yaml b/analysis_options.yaml index f0fabb4f..a3be6b82 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,29 +1 @@ -# This file configures the analyzer, which statically analyzes Dart code to -# check for errors, warnings, and lints. -# -# The issues identified by the analyzer are surfaced in the UI of Dart-enabled -# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be -# invoked from the command line by running `flutter analyze`. - -# The following line activates a set of recommended lints for Flutter apps, -# packages, and plugins designed to encourage good coding practices. -include: package:flutter_lints/flutter.yaml - -linter: - # The lint rules applied to this project can bpackage:flutter_lints/flutter.yamle customized in the - # section below to disable rules from the `package:flutter_lints/flutter.yaml` - # included above or to enable additional rules. A list of all available lints - # and their documentation is published at - # https://dart-lang.github.io/linter/lints/index.html. - # - # Instead of disabling a lint rule for the entire project in the - # section below, it can also be suppressed for a single line of code - # or a specific dart file by using the `// ignore: name_of_lint` and - # `// ignore_for_file: name_of_lint` syntax on the line or in the file - # producing the lint. - rules: - avoid_print: true # Uncomment to disable the `avoid_print` rule -# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule - -# Additional information about this file can be found at -# https://dart.dev/guides/language/analysis-options \ No newline at end of file +include: package:flutter_lints/flutter.yaml \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 08e3522f..83311d87 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,6 +1,3 @@ -import 'dart:typed_data'; -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_painter/flutter_painter.dart'; @@ -12,25 +9,22 @@ import 'package:phosphor_flutter/phosphor_flutter.dart'; void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); @override Widget build(BuildContext context) { - return MaterialApp( - debugShowCheckedModeBanner: false, + return const MaterialApp( + home: FlutterPainterExample(), title: "Flutter Painter Example", - theme: ThemeData( - primaryColor: Colors.brown, accentColor: Colors.amberAccent), - home: const FlutterPainterExample(), ); } } class FlutterPainterExample extends StatefulWidget { - const FlutterPainterExample({Key? key}) : super(key: key); + const FlutterPainterExample({super.key}); @override - _FlutterPainterExampleState createState() => _FlutterPainterExampleState(); + State createState() => _FlutterPainterExampleState(); } class _FlutterPainterExampleState extends State { @@ -133,8 +127,8 @@ class _FlutterPainterExampleState extends State { actions: [ // Delete the selected drawable IconButton( - icon: const Icon( - PhosphorIcons.trash, + icon: PhosphorIcon( + PhosphorIcons.trash(), ), onPressed: controller.selectedObjectDrawable == null ? null @@ -152,15 +146,15 @@ class _FlutterPainterExampleState extends State { ), // Redo action IconButton( - icon: const Icon( - PhosphorIcons.arrowClockwise, + icon: PhosphorIcon( + PhosphorIcons.arrowClockwise(), ), onPressed: controller.canRedo ? redo : null, ), // Undo action IconButton( - icon: const Icon( - PhosphorIcons.arrowCounterClockwise, + icon: PhosphorIcon( + PhosphorIcons.arrowCounterClockwise(), ), onPressed: controller.canUndo ? undo : null, ), @@ -170,10 +164,10 @@ class _FlutterPainterExampleState extends State { ), // Generate image floatingActionButton: FloatingActionButton( - child: const Icon( - PhosphorIcons.imageFill, - ), onPressed: renderAndDisplayImage, + child: PhosphorIcon( + PhosphorIcons.image(PhosphorIconsStyle.fill), + ), ), body: Stack( children: [ @@ -394,38 +388,38 @@ class _FlutterPainterExampleState extends State { children: [ // Free-style eraser IconButton( - icon: Icon( - PhosphorIcons.eraser, + icon: PhosphorIcon( + PhosphorIcons.eraser(), color: controller.freeStyleMode == FreeStyleMode.erase - ? Theme.of(context).accentColor + ? Theme.of(context).colorScheme.secondary : null, ), onPressed: toggleFreeStyleErase, ), // Free-style drawing IconButton( - icon: Icon( - PhosphorIcons.scribbleLoop, + icon: PhosphorIcon( + PhosphorIcons.scribbleLoop(), color: controller.freeStyleMode == FreeStyleMode.draw - ? Theme.of(context).accentColor + ? Theme.of(context).colorScheme.secondary : null, ), onPressed: toggleFreeStyleDraw, ), // Add text IconButton( - icon: Icon( - PhosphorIcons.textT, + icon: PhosphorIcon( + PhosphorIcons.textT(), color: textFocusNode.hasFocus - ? Theme.of(context).accentColor + ? Theme.of(context).colorScheme.secondary : null, ), onPressed: addText, ), // Add sticker image IconButton( - icon: const Icon( - PhosphorIcons.sticker, + icon: PhosphorIcon( + PhosphorIcons.sticker(), ), onPressed: addSticker, ), @@ -460,7 +454,7 @@ class _FlutterPainterExampleState extends State { child: Icon( getShapeIcon(controller.shapeFactory), color: controller.shapeFactory != null - ? Theme.of(context).accentColor + ? Theme.of(context).colorScheme.secondary : null, ), ), @@ -469,7 +463,7 @@ class _FlutterPainterExampleState extends State { IconButton( icon: Icon( getShapeIcon(controller.shapeFactory), - color: Theme.of(context).accentColor, + color: Theme.of(context).colorScheme.secondary, ), onPressed: () => selectShape(null), ), @@ -484,14 +478,16 @@ class _FlutterPainterExampleState extends State { } static IconData getShapeIcon(ShapeFactory? shapeFactory) { - if (shapeFactory is LineFactory) return PhosphorIcons.lineSegment; - if (shapeFactory is ArrowFactory) return PhosphorIcons.arrowUpRight; + if (shapeFactory is LineFactory) return PhosphorIcons.lineSegment(); + if (shapeFactory is ArrowFactory) return PhosphorIcons.arrowUpRight(); if (shapeFactory is DoubleArrowFactory) { - return PhosphorIcons.arrowsHorizontal; + return PhosphorIcons.arrowsHorizontal(); + } + if (shapeFactory is RectangleFactory) { + return PhosphorIcons.rectangle(); } - if (shapeFactory is RectangleFactory) return PhosphorIcons.rectangle; - if (shapeFactory is OvalFactory) return PhosphorIcons.circle; - return PhosphorIcons.polygon; + if (shapeFactory is OvalFactory) return PhosphorIcons.circle(); + return PhosphorIcons.polygon(); } void undo() { @@ -607,8 +603,7 @@ class _FlutterPainterExampleState extends State { class RenderedImageDialog extends StatelessWidget { final Future imageFuture; - const RenderedImageDialog({Key? key, required this.imageFuture}) - : super(key: key); + const RenderedImageDialog({super.key, required this.imageFuture}); @override Widget build(BuildContext context) { @@ -637,8 +632,7 @@ class RenderedImageDialog extends StatelessWidget { class SelectStickerImageDialog extends StatelessWidget { final List imagesLinks; - const SelectStickerImageDialog({Key? key, this.imagesLinks = const []}) - : super(key: key); + const SelectStickerImageDialog({super.key, this.imagesLinks = const []}); @override Widget build(BuildContext context) { diff --git a/example/pubspec.lock b/example/pubspec.lock index 53535720..7da3bc52 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -5,51 +5,50 @@ packages: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: transitive description: name: collection - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "1.16.0" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "1.3.0" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -59,16 +58,17 @@ packages: dependency: "direct dev" description: name: flutter_lints - url: "https://pub.dartlang.org" + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 + url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "3.0.1" flutter_painter: dependency: "direct main" description: path: ".." relative: true source: path - version: "1.0.1" + version: "1.1.0" flutter_test: dependency: "direct dev" description: flutter @@ -78,44 +78,50 @@ packages: dependency: transitive description: name: lints - url: "https://pub.dartlang.org" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "3.0.0" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + url: "https://pub.dev" source: hosted - version: "1.7.0" + version: "1.10.0" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.8.1" + version: "1.8.3" phosphor_flutter: dependency: "direct main" description: name: phosphor_flutter - url: "https://pub.dartlang.org" + sha256: "3b3e6e4cbda8208f8c1431b0999842f0b76db73853dd824fd4847a9f0166931a" + url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "2.0.1" sky_engine: dependency: transitive description: flutter @@ -125,51 +131,66 @@ packages: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" source: hosted - version: "0.4.9" + version: "0.6.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "2.1.2" + version: "2.1.4" + web: + dependency: transitive + description: + name: web + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + url: "https://pub.dev" + source: hosted + version: "0.3.0" sdks: - dart: ">=2.17.0-0 <3.0.0" + dart: ">=3.2.0 <4.0.0" flutter: ">=1.17.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index a204c34c..7bfdf411 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,76 +1,22 @@ name: example description: An example on how to use the flutter_painter package. - -# The following line prevents the package from being accidentally published to -# pub.dev using `pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev - -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +publish_to: none version: 1.0.0+1 environment: - sdk: ">=2.12.0 <3.0.0" + sdk: ^3.2.0 dependencies: flutter: sdk: flutter - flutter_painter: path: ../ - phosphor_flutter: ^1.4.0 + phosphor_flutter: ^2.0.1 dev_dependencies: - flutter_lints: ^1.0.4 + flutter_lints: ^3.0.1 flutter_test: sdk: flutter -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter. flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. - uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages + uses-material-design: true \ No newline at end of file diff --git a/lib/src/controllers/drawables/background/color_background_drawable.dart b/lib/src/controllers/drawables/background/color_background_drawable.dart index f3e102e5..5da626ca 100644 --- a/lib/src/controllers/drawables/background/color_background_drawable.dart +++ b/lib/src/controllers/drawables/background/color_background_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/cupertino.dart'; import 'background_drawable.dart'; diff --git a/lib/src/controllers/drawables/grouped_drawable.dart b/lib/src/controllers/drawables/grouped_drawable.dart index 8dd692bc..66424680 100644 --- a/lib/src/controllers/drawables/grouped_drawable.dart +++ b/lib/src/controllers/drawables/grouped_drawable.dart @@ -9,9 +9,8 @@ class GroupedDrawable extends Drawable { /// Creates a new [GroupedDrawable] with the list of [drawables]. GroupedDrawable({ required List drawables, - bool hidden = false, - }) : drawables = List.unmodifiable(drawables), - super(hidden: hidden); + super.hidden, + }) : drawables = List.unmodifiable(drawables); /// Draw all the drawables in the group on [canvas] of [size]. @override diff --git a/lib/src/controllers/drawables/image_drawable.dart b/lib/src/controllers/drawables/image_drawable.dart index a321483a..a04d5be8 100644 --- a/lib/src/controllers/drawables/image_drawable.dart +++ b/lib/src/controllers/drawables/image_drawable.dart @@ -1,7 +1,5 @@ import 'dart:ui'; -import 'package:flutter/rendering.dart'; - import 'object_drawable.dart'; /// A drawable of an image as an object. @@ -14,24 +12,16 @@ class ImageDrawable extends ObjectDrawable { /// Creates an [ImageDrawable] with the given [image]. ImageDrawable({ - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, required this.image, this.flipped = false, - }) : super( - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - hidden: hidden, - locked: locked); + }); /// Creates an [ImageDrawable] with the given [image], and calculates the scale based on the given [size]. /// The scale will be calculated such that the size of the drawable fits into the provided size. diff --git a/lib/src/controllers/drawables/object_drawable.dart b/lib/src/controllers/drawables/object_drawable.dart index ccab8ba1..40785fbf 100644 --- a/lib/src/controllers/drawables/object_drawable.dart +++ b/lib/src/controllers/drawables/object_drawable.dart @@ -1,4 +1,3 @@ -import 'dart:ui'; import 'package:flutter/material.dart'; import 'drawable.dart'; @@ -61,9 +60,8 @@ abstract class ObjectDrawable extends Drawable { this.assists = const {}, this.assistPaints = const {}, this.locked = false, - bool hidden = false, - }) : scale = scale < minScale ? minScale : scale, - super(hidden: hidden); + super.hidden, + }) : scale = scale < minScale ? minScale : scale; /// Draws any assist lines that the object has on [canvas] with [size]. void drawAssists(Canvas canvas, Size size) { diff --git a/lib/src/controllers/drawables/path/erase_drawable.dart b/lib/src/controllers/drawables/path/erase_drawable.dart index fc60dfad..5653f067 100644 --- a/lib/src/controllers/drawables/path/erase_drawable.dart +++ b/lib/src/controllers/drawables/path/erase_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/material.dart'; import 'path_drawable.dart'; @@ -9,10 +7,10 @@ class EraseDrawable extends PathDrawable { /// /// The path will be erased with the passed [strokeWidth] if provided. EraseDrawable({ - required List path, - double strokeWidth = 1, - bool hidden = false, - }) : super(path: path, strokeWidth: strokeWidth, hidden: hidden); + required super.path, + super.strokeWidth, + super.hidden, + }); /// Creates a copy of this but with the given fields replaced with the new values. @override diff --git a/lib/src/controllers/drawables/path/free_style_drawable.dart b/lib/src/controllers/drawables/path/free_style_drawable.dart index 9835dc01..f16b59dc 100644 --- a/lib/src/controllers/drawables/path/free_style_drawable.dart +++ b/lib/src/controllers/drawables/path/free_style_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/material.dart'; import 'path_drawable.dart'; @@ -13,18 +11,17 @@ class FreeStyleDrawable extends PathDrawable { /// /// The path will be drawn with the passed [color] and [strokeWidth] if provided. FreeStyleDrawable({ - required List path, - double strokeWidth = 1, + required super.path, + super.strokeWidth, this.color = Colors.black, - bool hidden = false, + super.hidden, }) : // An empty path cannot be drawn, so it is an invalid argument. assert(path.isNotEmpty, 'The path cannot be an empty list'), // The line cannot have a non-positive stroke width. assert(strokeWidth > 0, - 'The stroke width cannot be less than or equal to 0'), - super(path: path, strokeWidth: strokeWidth, hidden: hidden); + 'The stroke width cannot be less than or equal to 0'); /// Creates a copy of this but with the given fields replaced with the new values. @override diff --git a/lib/src/controllers/drawables/path/path_drawable.dart b/lib/src/controllers/drawables/path/path_drawable.dart index c6acaf90..a1b9ec16 100644 --- a/lib/src/controllers/drawables/path/path_drawable.dart +++ b/lib/src/controllers/drawables/path/path_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/material.dart'; import '../drawable.dart'; @@ -18,15 +16,14 @@ abstract class PathDrawable extends Drawable { PathDrawable({ required this.path, this.strokeWidth = 1, - bool hidden = false, + super.hidden, }) : // An empty path cannot be drawn, so it is an invalid argument. assert(path.isNotEmpty, 'The path cannot be an empty list'), // The line cannot have a non-positive stroke width. assert(strokeWidth > 0, - 'The stroke width cannot be less than or equal to 0'), - super(hidden: hidden); + 'The stroke width cannot be less than or equal to 0'); /// Creates a copy of this but with the given fields replaced with the new values. PathDrawable copyWith({ diff --git a/lib/src/controllers/drawables/shape/arrow_drawable.dart b/lib/src/controllers/drawables/shape/arrow_drawable.dart index bdc42997..4e1357c1 100644 --- a/lib/src/controllers/drawables/shape/arrow_drawable.dart +++ b/lib/src/controllers/drawables/shape/arrow_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -23,25 +21,15 @@ class ArrowDrawable extends Sized1DDrawable implements ShapeDrawable { ArrowDrawable({ Paint? paint, this.arrowHeadSize, - required double length, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, - }) : paint = paint ?? ShapeDrawable.defaultPaint, - super( - length: length, - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + required super.length, + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, + }) : paint = paint ?? ShapeDrawable.defaultPaint; /// The actual arrow head size used in drawing. double get _arrowHeadSize => arrowHeadSize ?? paint.strokeWidth * 3; diff --git a/lib/src/controllers/drawables/shape/double_arrow_drawable.dart b/lib/src/controllers/drawables/shape/double_arrow_drawable.dart index c23c5c79..9bbb9523 100644 --- a/lib/src/controllers/drawables/shape/double_arrow_drawable.dart +++ b/lib/src/controllers/drawables/shape/double_arrow_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -23,25 +21,15 @@ class DoubleArrowDrawable extends Sized1DDrawable implements ShapeDrawable { DoubleArrowDrawable({ Paint? paint, this.arrowHeadSize, - required double length, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, - }) : paint = paint ?? ShapeDrawable.defaultPaint, - super( - length: length, - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + required super.length, + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, + }) : paint = paint ?? ShapeDrawable.defaultPaint; /// The actual arrow head size used in drawing. double get _arrowHeadSize => arrowHeadSize ?? paint.strokeWidth * 3; diff --git a/lib/src/controllers/drawables/shape/line_drawable.dart b/lib/src/controllers/drawables/shape/line_drawable.dart index 0e34d03e..6453adaa 100644 --- a/lib/src/controllers/drawables/shape/line_drawable.dart +++ b/lib/src/controllers/drawables/shape/line_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -16,25 +14,15 @@ class LineDrawable extends Sized1DDrawable implements ShapeDrawable { /// Creates a new [LineDrawable] with the given [length] and [paint]. LineDrawable({ Paint? paint, - required double length, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, - }) : paint = paint ?? ShapeDrawable.defaultPaint, - super( - length: length, - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + required super.length, + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, + }) : paint = paint ?? ShapeDrawable.defaultPaint; /// Getter for padding of drawable. /// diff --git a/lib/src/controllers/drawables/shape/oval_drawable.dart b/lib/src/controllers/drawables/shape/oval_drawable.dart index 6887116a..191514e9 100644 --- a/lib/src/controllers/drawables/shape/oval_drawable.dart +++ b/lib/src/controllers/drawables/shape/oval_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -16,25 +14,15 @@ class OvalDrawable extends Sized2DDrawable implements ShapeDrawable { /// Creates a new [OvalDrawable] with the given [size] and [paint]. OvalDrawable({ Paint? paint, - required Size size, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, - }) : paint = paint ?? ShapeDrawable.defaultPaint, - super( - size: size, - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + required super.size, + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, + }) : paint = paint ?? ShapeDrawable.defaultPaint; /// Getter for padding of drawable. /// diff --git a/lib/src/controllers/drawables/shape/rectangle_drawable.dart b/lib/src/controllers/drawables/shape/rectangle_drawable.dart index 4bf1b53e..5e6f51f4 100644 --- a/lib/src/controllers/drawables/shape/rectangle_drawable.dart +++ b/lib/src/controllers/drawables/shape/rectangle_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -20,26 +18,16 @@ class RectangleDrawable extends Sized2DDrawable implements ShapeDrawable { /// Creates a new [RectangleDrawable] with the given [size], [paint] and [borderRadius]. RectangleDrawable({ Paint? paint, - required Size size, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, + required super.size, + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, this.borderRadius = const BorderRadius.all(Radius.circular(5)), - }) : paint = paint ?? ShapeDrawable.defaultPaint, - super( - size: size, - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + }) : paint = paint ?? ShapeDrawable.defaultPaint; /// Getter for padding of drawable. /// diff --git a/lib/src/controllers/drawables/shape/shape_drawable.dart b/lib/src/controllers/drawables/shape/shape_drawable.dart index 588fddb4..5c449c6c 100644 --- a/lib/src/controllers/drawables/shape/shape_drawable.dart +++ b/lib/src/controllers/drawables/shape/shape_drawable.dart @@ -17,23 +17,14 @@ abstract class ShapeDrawable extends ObjectDrawable { /// Default constructor for [ObjectDrawable]. ShapeDrawable({ Paint? paint, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, - }) : paint = paint ?? defaultPaint, - super( - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, + }) : paint = paint ?? defaultPaint; /// Creates a copy of this but with the given fields replaced with the new values. @override diff --git a/lib/src/controllers/drawables/sized1ddrawable.dart b/lib/src/controllers/drawables/sized1ddrawable.dart index 40fdc810..a5b65536 100644 --- a/lib/src/controllers/drawables/sized1ddrawable.dart +++ b/lib/src/controllers/drawables/sized1ddrawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -16,22 +14,14 @@ abstract class Sized1DDrawable extends ObjectDrawable { /// Creates a new [Sized1DDrawable] with the given [length] and [padding]. const Sized1DDrawable({ required this.length, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, - }) : super( - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, + }); /// Getter for padding of drawable. /// diff --git a/lib/src/controllers/drawables/sized2ddrawable.dart b/lib/src/controllers/drawables/sized2ddrawable.dart index aa903ba5..1facb9a7 100644 --- a/lib/src/controllers/drawables/sized2ddrawable.dart +++ b/lib/src/controllers/drawables/sized2ddrawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/foundation.dart'; import 'package:flutter/rendering.dart'; @@ -13,22 +11,14 @@ abstract class Sized2DDrawable extends ObjectDrawable { /// Creates a new [Sized2DDrawable] with the given [size] and [painting]. const Sized2DDrawable({ required this.size, - required Offset position, - double rotationAngle = 0, - double scale = 1, - Set assists = const {}, - Map assistPaints = - const {}, - bool locked = false, - bool hidden = false, - }) : super( - position: position, - rotationAngle: rotationAngle, - scale: scale, - assists: assists, - assistPaints: assistPaints, - locked: locked, - hidden: hidden); + required super.position, + super.rotationAngle, + super.scale, + super.assists, + super.assistPaints, + super.locked, + super.hidden, + }); /// Getter for padding of drawable. /// diff --git a/lib/src/controllers/drawables/text_drawable.dart b/lib/src/controllers/drawables/text_drawable.dart index afba2e4f..28e424bb 100644 --- a/lib/src/controllers/drawables/text_drawable.dart +++ b/lib/src/controllers/drawables/text_drawable.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/material.dart'; import 'object_drawable.dart'; @@ -23,30 +21,24 @@ class TextDrawable extends ObjectDrawable { /// The path will be drawn with the passed [style] if provided. TextDrawable({ required this.text, - required Offset position, + required super.position, double rotation = 0, - double scale = 1, + super.scale, this.style = const TextStyle( fontSize: 14, color: Colors.black, ), this.direction = TextDirection.ltr, - bool locked = false, - bool hidden = false, - Set assists = const {}, + super.locked, + super.hidden, + super.assists, }) : textPainter = TextPainter( text: TextSpan(text: text, style: style), textAlign: TextAlign.center, - textScaleFactor: scale, + textScaler: TextScaler.linear(scale), textDirection: direction, ), - super( - position: position, - rotationAngle: rotation, - scale: scale, - assists: assists, - locked: locked, - hidden: hidden); + super(rotationAngle: rotation); /// Draws the text on the provided [canvas] of size [size]. @override diff --git a/lib/src/controllers/factories/rectangle_factory.dart b/lib/src/controllers/factories/rectangle_factory.dart index 330e6587..c2cf79c2 100644 --- a/lib/src/controllers/factories/rectangle_factory.dart +++ b/lib/src/controllers/factories/rectangle_factory.dart @@ -1,5 +1,3 @@ -import 'dart:ui'; - import 'package:flutter/rendering.dart'; import '../drawables/shape/rectangle_drawable.dart'; diff --git a/lib/src/controllers/helpers/border_box_shadow.dart b/lib/src/controllers/helpers/border_box_shadow.dart index e14d81c2..804fe3f9 100644 --- a/lib/src/controllers/helpers/border_box_shadow.dart +++ b/lib/src/controllers/helpers/border_box_shadow.dart @@ -4,21 +4,14 @@ import 'package:flutter/painting.dart'; /// /// This is used to show an outer shadow blur for object controls. class BorderBoxShadow extends BoxShadow { - /// The blur style to use. - final BlurStyle blurStyle; - /// Creates a new [BorderBoxShadow] with the given `blurStyle` and other arguments matching [BoxShadow]. const BorderBoxShadow({ - Color color = const Color(0xFF000000), - Offset offset = Offset.zero, - double blurRadius = 0.0, - double spreadRadius = 0.0, - this.blurStyle = BlurStyle.outer, - }) : super( - color: color, - offset: offset, - blurRadius: blurRadius, - spreadRadius: spreadRadius); + super.color = const Color(0xFF000000), + super.offset = Offset.zero, + super.blurRadius = 0.0, + super.spreadRadius = 0.0, + super.blurStyle = BlurStyle.outer, + }); /// Create the [Paint] object that corresponds to this shadow description. /// diff --git a/lib/src/controllers/notifications/drawable_created_notification.dart b/lib/src/controllers/notifications/drawable_created_notification.dart index 45d402b4..e78aca3e 100644 --- a/lib/src/controllers/notifications/drawable_created_notification.dart +++ b/lib/src/controllers/notifications/drawable_created_notification.dart @@ -4,5 +4,5 @@ import 'drawable_notification.dart'; /// A notification that is dispatched when a drawable is created internally in Flutter Painter. class DrawableCreatedNotification extends DrawableNotification { /// Creates a [DrawableCreatedNotification] with the given [drawable]. - DrawableCreatedNotification(drawable) : super(drawable); + DrawableCreatedNotification(super.drawable); } diff --git a/lib/src/controllers/notifications/drawable_deleted_notification.dart b/lib/src/controllers/notifications/drawable_deleted_notification.dart index 14402a0e..50cdbe03 100644 --- a/lib/src/controllers/notifications/drawable_deleted_notification.dart +++ b/lib/src/controllers/notifications/drawable_deleted_notification.dart @@ -4,5 +4,5 @@ import 'drawable_notification.dart'; /// A notification that is dispatched when a drawable is deleted internally in Flutter Painter. class DrawableDeletedNotification extends DrawableNotification { /// Creates a [DrawableDeletedNotification] with the given [drawable]. - DrawableDeletedNotification(drawable) : super(drawable); + DrawableDeletedNotification(super.drawable); } diff --git a/lib/src/controllers/notifications/object_reselected_notification.dart b/lib/src/controllers/notifications/object_reselected_notification.dart index 526b7059..182297b5 100644 --- a/lib/src/controllers/notifications/object_reselected_notification.dart +++ b/lib/src/controllers/notifications/object_reselected_notification.dart @@ -7,6 +7,5 @@ import 'drawable_notification.dart'; class ObjectDrawableReselectedNotification extends DrawableNotification { /// Creates a [ObjectDrawableReselectedNotification] with the given [drawable]. - ObjectDrawableReselectedNotification(ObjectDrawable? drawable) - : super(drawable); + ObjectDrawableReselectedNotification(super.drawable); } diff --git a/lib/src/controllers/notifications/selected_object_updated_notification.dart b/lib/src/controllers/notifications/selected_object_updated_notification.dart index 5d6fada4..bb749317 100644 --- a/lib/src/controllers/notifications/selected_object_updated_notification.dart +++ b/lib/src/controllers/notifications/selected_object_updated_notification.dart @@ -11,6 +11,5 @@ import 'drawable_notification.dart'; class SelectedObjectDrawableUpdatedNotification extends DrawableNotification { /// Creates a [SelectedObjectDrawableUpdatedNotification] with the given [drawable]. - SelectedObjectDrawableUpdatedNotification(ObjectDrawable? drawable) - : super(drawable); + SelectedObjectDrawableUpdatedNotification(super.drawable); } diff --git a/lib/src/controllers/painter_controller.dart b/lib/src/controllers/painter_controller.dart index f2de522f..eb29b173 100644 --- a/lib/src/controllers/painter_controller.dart +++ b/lib/src/controllers/painter_controller.dart @@ -62,11 +62,10 @@ class PainterController extends ValueNotifier { background: background)); /// Create a [PainterController] from a [PainterControllerValue]. - PainterController.fromValue(PainterControllerValue value) + PainterController.fromValue(super.value) : _eventsSteamController = StreamController.broadcast(), painterKey = GlobalKey(), - transformationController = TransformationController(), - super(value); + transformationController = TransformationController(); /// The stream of [PainterEvent]s dispatched from this controller. /// @@ -433,8 +432,8 @@ class PainterControllerValue { } @override - int get hashCode => hashValues( - hashList(_drawables), background, settings, selectedObjectDrawable); + int get hashCode => Object.hash( + Object.hashAll(_drawables), background, settings, selectedObjectDrawable); } /// Private class that is used internally to represent no diff --git a/lib/src/controllers/settings/painter_settings.dart b/lib/src/controllers/settings/painter_settings.dart index b3697268..293e9a83 100644 --- a/lib/src/controllers/settings/painter_settings.dart +++ b/lib/src/controllers/settings/painter_settings.dart @@ -1,9 +1,6 @@ export 'free_style_settings.dart'; import 'package:flutter/material.dart'; -import 'scale_settings.dart'; -import 'shape_settings.dart'; -import 'object_settings.dart'; import 'settings.dart'; /// Represents all the settings used to create and draw drawables. diff --git a/lib/src/extensions/paint_copy_extension.dart b/lib/src/extensions/paint_copy_extension.dart index a41ce194..8fa00e1e 100644 --- a/lib/src/extensions/paint_copy_extension.dart +++ b/lib/src/extensions/paint_copy_extension.dart @@ -1,7 +1,5 @@ import 'dart:ui'; -import 'package:flutter/painting.dart'; - import '../controllers/helpers/renderer_check/renderer_check.dart'; /// Extension to add a copy method for [Paint]. diff --git a/lib/src/extensions/painter_controller_helper_extension.dart b/lib/src/extensions/painter_controller_helper_extension.dart index 5e5372cc..81ccc526 100644 --- a/lib/src/extensions/painter_controller_helper_extension.dart +++ b/lib/src/extensions/painter_controller_helper_extension.dart @@ -1,9 +1,6 @@ -import 'package:flutter/rendering.dart'; import 'package:flutter/widgets.dart'; import '../controllers/factories/shape_factory.dart'; -import '../controllers/settings/shape_settings.dart'; - import '../controllers/painter_controller.dart'; import '../controllers/settings/settings.dart'; import '../controllers/drawables/drawables.dart'; diff --git a/lib/src/views/painters/painter.dart b/lib/src/views/painters/painter.dart index e9df3a6f..d5e7c04f 100644 --- a/lib/src/views/painters/painter.dart +++ b/lib/src/views/painters/painter.dart @@ -27,7 +27,7 @@ class Painter extends CustomPainter { @override void paint(Canvas canvas, Size size) { // This is to allow [_scale] to be upgraded to non-nullable after checking for null - final _scale = scale; + final scale = this.scale; // Draw the background if it was provided if (background != null && background!.isNotHidden) { @@ -36,10 +36,10 @@ class Painter extends CustomPainter { // If a scale size is being used, save the canvas (with the background), scale it // and then proceed to drawing the drawables - if (_scale != null) { + if (scale != null) { canvas.save(); canvas.transform(Matrix4.identity() - .scaled(size.width / _scale.width, size.height / _scale.height) + .scaled(size.width / scale.width, size.height / scale.height) .storage); } @@ -48,13 +48,13 @@ class Painter extends CustomPainter { // Draw all the drawables for (final drawable in drawables.where((drawable) => drawable.isNotHidden)) { - drawable.draw(canvas, _scale ?? size); + drawable.draw(canvas, scale ?? size); } canvas.restore(); // If a scale size is being used, restore the saved canvas, which will scale all the drawn drawables - if (_scale != null) { + if (scale != null) { canvas.restore(); } } diff --git a/lib/src/views/widgets/flutter_painter.dart b/lib/src/views/widgets/flutter_painter.dart index 201af62d..ef49383f 100644 --- a/lib/src/views/widgets/flutter_painter.dart +++ b/lib/src/views/widgets/flutter_painter.dart @@ -1,34 +1,36 @@ import 'dart:async'; +import 'dart:math' as math; import 'dart:math'; -import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; -import 'package:flutter/rendering.dart'; -import '../../controllers/events/selected_object_drawable_removed_event.dart'; -import '../../controllers/helpers/renderer_check/renderer_check.dart'; + import '../../controllers/drawables/drawable.dart'; -import '../../controllers/notifications/notifications.dart'; -import '../../controllers/drawables/sized1ddrawable.dart'; +import '../../controllers/drawables/object_drawable.dart'; +import '../../controllers/drawables/path/path_drawables.dart'; import '../../controllers/drawables/shape/shape_drawable.dart'; +import '../../controllers/drawables/sized1ddrawable.dart'; import '../../controllers/drawables/sized2ddrawable.dart'; -import '../../controllers/drawables/object_drawable.dart'; -import '../../controllers/events/events.dart'; import '../../controllers/drawables/text_drawable.dart'; -import '../../controllers/drawables/path/path_drawables.dart'; -import '../../controllers/settings/settings.dart'; -import '../painters/painter.dart'; -import '../../controllers/painter_controller.dart'; +import '../../controllers/events/events.dart'; +import '../../controllers/events/selected_object_drawable_removed_event.dart'; import '../../controllers/helpers/border_box_shadow.dart'; +import '../../controllers/helpers/renderer_check/renderer_check.dart'; +import '../../controllers/notifications/notifications.dart'; +import '../../controllers/painter_controller.dart'; +import '../../controllers/settings/settings.dart'; import '../../extensions/painter_controller_helper_extension.dart'; +import '../painters/painter.dart'; import 'painter_controller_widget.dart'; -import 'dart:math' as math; part 'free_style_widget.dart'; -part 'text_widget.dart'; + part 'object_widget.dart'; + part 'shape_widget.dart'; +part 'text_widget.dart'; + typedef DrawableCreatedCallback = Function(Drawable drawable); typedef DrawableDeletedCallback = Function(Drawable drawable); @@ -64,29 +66,27 @@ class FlutterPainter extends StatelessWidget { /// Creates a [FlutterPainter] with the given [controller] and optional callbacks. const FlutterPainter( - {Key? key, + {super.key, required this.controller, this.onDrawableCreated, this.onDrawableDeleted, this.onSelectedObjectDrawableChanged, this.onPainterSettingsChanged}) - : _builder = _defaultBuilder, - super(key: key); + : _builder = _defaultBuilder; /// Creates a [FlutterPainter] with the given [controller], [builder] and optional callbacks. /// /// Using this constructor, the [builder] will be called any time the [controller] updates. /// It is useful if you want to build UI that automatically rebuilds on updates from [controller]. const FlutterPainter.builder( - {Key? key, + {super.key, required this.controller, required FlutterPainterBuilderCallback builder, this.onDrawableCreated, this.onDrawableDeleted, this.onSelectedObjectDrawableChanged, this.onPainterSettingsChanged}) - : _builder = builder, - super(key: key); + : _builder = builder; @override Widget build(BuildContext context) { @@ -135,13 +135,12 @@ class _FlutterPainterWidget extends StatelessWidget { /// Creates a [_FlutterPainterWidget] with the given [controller] and optional callbacks. const _FlutterPainterWidget( - {Key? key, + {super.key, required this.controller, this.onDrawableCreated, this.onDrawableDeleted, this.onSelectedObjectDrawableChanged, - this.onPainterSettingsChanged}) - : super(key: key); + this.onPainterSettingsChanged}); @override Widget build(BuildContext context) { diff --git a/lib/src/views/widgets/free_style_widget.dart b/lib/src/views/widgets/free_style_widget.dart index 126bdb27..76279da3 100644 --- a/lib/src/views/widgets/free_style_widget.dart +++ b/lib/src/views/widgets/free_style_widget.dart @@ -6,10 +6,7 @@ class _FreeStyleWidget extends StatefulWidget { final Widget child; /// Creates a [_FreeStyleWidget] with the given [controller], [child] widget. - const _FreeStyleWidget({ - Key? key, - required this.child, - }) : super(key: key); + const _FreeStyleWidget({required this.child}); @override _FreeStyleWidgetState createState() => _FreeStyleWidgetState(); @@ -104,7 +101,7 @@ class _FreeStyleWidgetState extends State<_FreeStyleWidget> { /// Callback when the user removes all pointers from the widget. void _handleHorizontalDragUp() { - DrawableCreatedNotification(drawable).dispatch(context); + DrawableCreatedNotification(drawable!).dispatch(context); /// Reset the current drawable for the user to draw a new one next time drawable = null; diff --git a/lib/src/views/widgets/object_widget.dart b/lib/src/views/widgets/object_widget.dart index 885f9c07..521062b3 100644 --- a/lib/src/views/widgets/object_widget.dart +++ b/lib/src/views/widgets/object_widget.dart @@ -12,10 +12,9 @@ class _ObjectWidget extends StatefulWidget { /// Creates a [_ObjectWidget] with the given [controller], [child] widget. const _ObjectWidget({ - Key? key, required this.child, this.interactionEnabled = true, - }) : super(key: key); + }); @override _ObjectWidgetState createState() => _ObjectWidgetState(); @@ -140,17 +139,36 @@ class _ObjectWidgetState extends State<_ObjectWidget> { @override Widget build(BuildContext context) { final drawables = this.drawables; - final drawableAirTransformable = controller?.selectedObjectDrawable != null && controller?.shapeSettings.factory == null ; - final selectedDrawableEntry = drawableAirTransformable ? MapEntry (drawables.indexOf(controller!.selectedObjectDrawable!), controller!.selectedObjectDrawable!) : MapEntry (0, TextDrawable(position: Offset(0,0), text: '', )); + final drawableAirTransformable = + controller?.selectedObjectDrawable != null && + controller?.shapeSettings.factory == null; + final selectedDrawableEntry = drawableAirTransformable + ? MapEntry( + drawables.indexOf(controller!.selectedObjectDrawable!), + controller!.selectedObjectDrawable!) + : MapEntry( + 0, + TextDrawable( + position: const Offset(0, 0), + text: '', + )); return LayoutBuilder(builder: (context, constraints) { return Stack( children: [ Positioned.fill( child: GestureDetector( onTap: onBackgroundTapped, - onScaleStart: drawableAirTransformable ? (details) => onDrawableScaleStart(selectedDrawableEntry, details) : null, - onScaleUpdate: drawableAirTransformable ? (details) => onDrawableScaleUpdate(selectedDrawableEntry, details) : null, - onScaleEnd: drawableAirTransformable ? (_) => onDrawableScaleEnd(selectedDrawableEntry) : null, + onScaleStart: drawableAirTransformable + ? (details) => + onDrawableScaleStart(selectedDrawableEntry, details) + : null, + onScaleUpdate: drawableAirTransformable + ? (details) => + onDrawableScaleUpdate(selectedDrawableEntry, details) + : null, + onScaleEnd: drawableAirTransformable + ? (_) => onDrawableScaleEnd(selectedDrawableEntry) + : null, child: widget.child)), ...drawables.asMap().entries.map((entry) { final drawable = entry.value; @@ -1023,11 +1041,11 @@ class _ObjectWidgetState extends State<_ObjectWidget> { /// A callback that is called when a transformation occurs in the [InteractiveViewer] in the widget tree. void onTransformUpdated() { setState(() { - final _m4storage = + final m4storage = PainterController.of(context).transformationController.value; - transformationScale = math.sqrt(_m4storage[8] * _m4storage[8] + - _m4storage[9] * _m4storage[9] + - _m4storage[10] * _m4storage[10]); + transformationScale = math.sqrt(m4storage[8] * m4storage[8] + + m4storage[9] * m4storage[9] + + m4storage[10] * m4storage[10]); }); } } @@ -1040,45 +1058,23 @@ class _ObjectControlBox extends StatelessWidget { /// Whether the box is being used or not. final bool active; - /// Color of control when it is not active. - /// Defaults to [Colors.white]. - final Color inactiveColor; - - /// Color of control when it is active. - /// If null is provided, the theme's accent color is used. If there is no theme, [Colors.blue] is used. - final Color? activeColor; - - /// Color of the shadow surrounding the control. - /// Defaults to [Colors.black]. - final Color shadowColor; - /// Creates an [_ObjectControlBox] with the given [shape] and [active]. /// /// By default, it will be a [BoxShape.rectangle] shape and not active. const _ObjectControlBox({ - Key? key, this.shape = BoxShape.rectangle, this.active = false, - this.inactiveColor = Colors.white, - this.activeColor, - this.shadowColor = Colors.black, - }) : super(key: key); + }); @override Widget build(BuildContext context) { - ThemeData? theme = Theme.of(context); - if (theme == ThemeData.fallback()) theme = null; - final activeColor = this.activeColor ?? theme?.accentColor ?? Colors.blue; return AnimatedContainer( duration: _ObjectWidgetState.controlsTransitionDuration, decoration: BoxDecoration( - color: active ? activeColor : inactiveColor, + color: active ? Theme.of(context).colorScheme.secondary : Colors.white, shape: shape, - boxShadow: [ - BoxShadow( - color: shadowColor, - blurRadius: 2, - ) + boxShadow: const [ + BoxShadow(blurRadius: 2), ], ), ); diff --git a/lib/src/views/widgets/painter_controller_widget.dart b/lib/src/views/widgets/painter_controller_widget.dart index 8a3acea6..132c2359 100644 --- a/lib/src/views/widgets/painter_controller_widget.dart +++ b/lib/src/views/widgets/painter_controller_widget.dart @@ -3,10 +3,10 @@ import '../../controllers/painter_controller.dart'; class PainterControllerWidget extends InheritedWidget { const PainterControllerWidget({ - Key? key, + super.key, required this.controller, - required Widget child, - }) : super(key: key, child: child); + required super.child, + }); final PainterController controller; diff --git a/lib/src/views/widgets/shape_widget.dart b/lib/src/views/widgets/shape_widget.dart index ed28e9b6..5630f198 100644 --- a/lib/src/views/widgets/shape_widget.dart +++ b/lib/src/views/widgets/shape_widget.dart @@ -6,10 +6,7 @@ class _ShapeWidget extends StatefulWidget { final Widget child; /// Creates a [_ShapeWidget] with the given [controller], [child] widget. - const _ShapeWidget({ - Key? key, - required this.child, - }) : super(key: key); + const _ShapeWidget({required this.child}); @override _ShapeWidgetState createState() => _ShapeWidgetState(); @@ -109,7 +106,7 @@ class _ShapeWidgetState extends State<_ShapeWidget> { .dispatch(context); } - DrawableCreatedNotification(currentShapeDrawable).dispatch(context); + DrawableCreatedNotification(currentShapeDrawable!).dispatch(context); setState(() { currentShapeDrawable = null; diff --git a/lib/src/views/widgets/text_widget.dart b/lib/src/views/widgets/text_widget.dart index c1a379cb..2a78f98c 100644 --- a/lib/src/views/widgets/text_widget.dart +++ b/lib/src/views/widgets/text_widget.dart @@ -6,10 +6,7 @@ class _TextWidget extends StatefulWidget { final Widget child; /// Creates a [_TextWidget] with the given [controller] and [child] widget. - const _TextWidget({ - Key? key, - required this.child, - }) : super(key: key); + const _TextWidget({required this.child}); @override _TextWidgetState createState() => _TextWidgetState(); @@ -152,11 +149,11 @@ class EditTextWidget extends StatefulWidget { final bool isNew; const EditTextWidget({ - Key? key, + super.key, required this.controller, required this.drawable, this.isNew = false, - }) : super(key: key); + }); @override EditTextWidgetState createState() => EditTextWidgetState(); @@ -276,7 +273,7 @@ class EditTextWidgetState extends State @override void didChangeMetrics() { super.didChangeMetrics(); - final value = WidgetsBinding.instance.window.viewInsets.bottom; + final value = View.of(context).viewInsets.bottom; // If the previous value of bottom view insets is larger than the current value, // the keyboard is closing, so lose focus from the focus node diff --git a/pubspec.lock b/pubspec.lock index 3658ec1c..d55e762a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,104 +1,54 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - _fe_analyzer_shared: - dependency: transitive - description: - name: _fe_analyzer_shared - url: "https://pub.dartlang.org" - source: hosted - version: "41.0.0" - analyzer: - dependency: transitive - description: - name: analyzer - url: "https://pub.dartlang.org" - source: hosted - version: "4.2.0" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "2.3.0" async: dependency: transitive description: name: async - url: "https://pub.dartlang.org" + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" source: hosted - version: "2.8.2" + version: "2.11.0" boolean_selector: dependency: transitive description: name: boolean_selector - url: "https://pub.dartlang.org" + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.1" characters: dependency: transitive description: name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" source: hosted - version: "1.3.1" + version: "1.3.0" clock: dependency: transitive description: name: clock - url: "https://pub.dartlang.org" + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.1.1" collection: dependency: "direct main" description: name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.16.0" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.1" - coverage: - dependency: transitive - description: - name: coverage - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.3" - crypto: - dependency: transitive - description: - name: crypto - url: "https://pub.dartlang.org" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "1.18.0" fake_async: dependency: transitive description: name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" - file: - dependency: transitive - description: - name: file - url: "https://pub.dartlang.org" + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" source: hosted - version: "6.1.2" + version: "1.3.1" flutter: dependency: "direct main" description: flutter @@ -108,299 +58,131 @@ packages: dependency: "direct dev" description: name: flutter_lints - url: "https://pub.dartlang.org" + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 + url: "https://pub.dev" source: hosted - version: "1.0.4" + version: "3.0.1" flutter_test: dependency: "direct dev" description: flutter source: sdk version: "0.0.0" - frontend_server_client: - dependency: transitive - description: - name: frontend_server_client - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.3" - glob: - dependency: transitive - description: - name: glob - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" - http_multi_server: - dependency: transitive - description: - name: http_multi_server - url: "https://pub.dartlang.org" - source: hosted - version: "3.2.0" - http_parser: - dependency: transitive - description: - name: http_parser - url: "https://pub.dartlang.org" - source: hosted - version: "4.0.0" - io: - dependency: transitive - description: - name: io - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.3" - js: - dependency: transitive - description: - name: js - url: "https://pub.dartlang.org" - source: hosted - version: "0.6.3" lints: dependency: transitive description: name: lints - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" - logging: - dependency: transitive - description: - name: logging - url: "https://pub.dartlang.org" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "3.0.0" matcher: dependency: transitive description: name: matcher - url: "https://pub.dartlang.org" + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" + url: "https://pub.dev" source: hosted - version: "0.12.11" + version: "0.12.16" material_color_utilities: dependency: transitive description: name: material_color_utilities - url: "https://pub.dartlang.org" + sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + url: "https://pub.dev" source: hosted - version: "0.1.4" + version: "0.5.0" meta: dependency: transitive description: name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.7.0" - mime: - dependency: transitive - description: - name: mime - url: "https://pub.dartlang.org" + sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + url: "https://pub.dev" source: hosted - version: "1.0.1" + version: "1.10.0" mocktail: dependency: "direct dev" description: name: mocktail - url: "https://pub.dartlang.org" + sha256: bac151b31e4ed78bd59ab89aa4c0928f297b1180186d5daf03734519e5f596c1 + url: "https://pub.dev" source: hosted - version: "0.3.0-dev.1" - node_preamble: - dependency: transitive - description: - name: node_preamble - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.1" - package_config: - dependency: transitive - description: - name: package_config - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.2" + version: "1.0.1" path: dependency: transitive description: name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.1" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.11.1" - pool: - dependency: transitive - description: - name: pool - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.0" - pub_semver: - dependency: transitive - description: - name: pub_semver - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - shelf: - dependency: transitive - description: - name: shelf - url: "https://pub.dartlang.org" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + url: "https://pub.dev" source: hosted - version: "1.2.0" - shelf_packages_handler: - dependency: transitive - description: - name: shelf_packages_handler - url: "https://pub.dartlang.org" - source: hosted - version: "3.0.0" - shelf_static: - dependency: transitive - description: - name: shelf_static - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - shelf_web_socket: - dependency: transitive - description: - name: shelf_web_socket - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" + version: "1.8.3" sky_engine: dependency: transitive description: flutter source: sdk version: "0.0.99" - source_map_stack_trace: - dependency: transitive - description: - name: source_map_stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - source_maps: - dependency: transitive - description: - name: source_maps - url: "https://pub.dartlang.org" - source: hosted - version: "0.10.10" source_span: dependency: transitive description: name: source_span - url: "https://pub.dartlang.org" + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" source: hosted - version: "1.8.2" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - url: "https://pub.dartlang.org" + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - url: "https://pub.dartlang.org" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "2.1.2" string_scanner: dependency: transitive description: name: string_scanner - url: "https://pub.dartlang.org" + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.0" term_glyph: dependency: transitive description: name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - test: - dependency: transitive - description: - name: test - url: "https://pub.dartlang.org" + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" source: hosted - version: "1.21.1" + version: "1.2.1" test_api: dependency: transitive description: name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.4.9" - test_core: - dependency: transitive - description: - name: test_core - url: "https://pub.dartlang.org" + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + url: "https://pub.dev" source: hosted - version: "0.4.13" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.3.0" + version: "0.6.1" vector_math: dependency: transitive description: name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.2" - vm_service: - dependency: transitive - description: - name: vm_service - url: "https://pub.dartlang.org" - source: hosted - version: "6.2.0" - watcher: - dependency: transitive - description: - name: watcher - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - web_socket_channel: - dependency: transitive - description: - name: web_socket_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.0" - webkit_inspection_protocol: - dependency: transitive - description: - name: webkit_inspection_protocol - url: "https://pub.dartlang.org" + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" source: hosted - version: "1.0.0" - yaml: + version: "2.1.4" + web: dependency: transitive description: - name: yaml - url: "https://pub.dartlang.org" + name: web + sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "0.3.0" sdks: - dart: ">=2.17.0 <3.0.0" - flutter: ">=1.17.0" + dart: ">=3.2.0 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index e116ab25..c044c2d7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,24 +1,23 @@ name: flutter_painter -version: 1.0.1 +version: 1.1.0 description: A Flutter widget to draw scribbles, text, shapes and images on a background image or color homepage: https://github.com/omarhurani/flutter_painter repository: https://github.com/omarhurani/flutter_painter issue_tracker: https://github.com/omarhurani/flutter_painter/issues environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=1.17.0" + sdk: ^3.2.0 dependencies: + collection: ^1.18.0 flutter: sdk: flutter - collection: ^1.15.0 - dev_dependencies: - flutter_lints: ^1.0.4 + flutter_lints: ^3.0.1 flutter_test: sdk: flutter - mocktail: ^0.3.0-dev.1 + mocktail: ^1.0.1 flutter: + uses-material-design: true \ No newline at end of file diff --git a/test/widget_test_utils.dart b/test/widget_test_utils.dart index 3542da90..2576605b 100644 --- a/test/widget_test_utils.dart +++ b/test/widget_test_utils.dart @@ -5,7 +5,6 @@ import 'package:flutter_test/flutter_test.dart'; /// Simple wrapper for testing specific widget /// so that we don't need to write things multiple times class WidgetTestbed { - /// In case that we want to specify platform for running tests Future withPlatform( final TargetPlatform platform, @@ -34,10 +33,10 @@ class WidgetTestbed { final WidgetTester tester, [ final Size size = const Size(30000, 30000), ]) { - tester.binding.window.physicalSizeTestValue = size; + tester.view.physicalSize = size; } void clearPhysicalSize(final WidgetTester tester) { - tester.binding.window.clearPhysicalSizeTestValue(); + tester.view.resetPhysicalSize(); } }