diff --git a/CHANGELOG.md b/CHANGELOG.md index 57da05b..c303961 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,13 @@ +# 1.0.0 + +* **New**: added the `fx()` and `wt()` extension functions to the `num` class to simplify the creation of `Fixed` and `Weight` cell sizes. +* **New**: added the `cell()` and `implicitCell()` extension functions to the `Widget` class to simplify the creation of `Cell` and `Cell.implicit` widgets. +* Minimum Flutter SDK is **3.0.0** + # 0.9.0 -Update version +* Version update # 0.0.9 -First public release +* **New**: first public release diff --git a/README.md b/README.md index cc96fe3..85defb5 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,18 @@ GridPad( ); ``` +Instead of using `Weight` and `Fixed` explicitly, the appropriate extension functions can be used: + +```dart +GridPad( + gridPadCells: GridPadCellsBuilder(rowCount: 3, columnCount: 4) + .rowSize(0, 2.wt()) + .columnSize(3, 90.fx()) + .build(), + children: [], +); +``` + ![custom_define_grid_dark](https://github.com/landarskiy/gridpad_flutter/assets/2251498/4a769913-c84d-427c-8f1b-10a1574d2bf2) The algorithm for allocating available space between cells: @@ -136,6 +148,18 @@ GridPad( ); ``` +Alternatively, instead of the Cell widget, `Widget.cell()` extension functions can be applied: + +```dart +GridPad( + gridPadCells: GridPadCells.gridSize(rowCount: 3, columnCount: 4), + children: [ + ChildWidget().cell(row: 1, column: 2), + ChildWidget().cell(row: 0, column: 1), + ], +); +``` + ![place_items_specific_dark](https://github.com/landarskiy/gridpad_flutter/assets/2251498/f1bf96e4-f7d2-4614-bda6-4e90ff18a741) > :warning: A cell can contain more than one item. The draw order will be the same as the place @@ -216,13 +240,7 @@ GridPad( children: [ // will be skipped in a drawing process because the item is placed in the column range [3;5] // but the maximum allowable is 3 - Cell( - row: 1, - column: 3 - rowSpan: 1, - columnSpan: 3, - child: ChildWidget(), - ), + ChildWidget().cell(row: 1, column: 3, rowSpan: 1, columnSpan: 3), ], ); ``` @@ -238,7 +256,7 @@ parameter - **anchor**. The anchor is the point in the corner from which the spa The value depends on `horizontalPolicy` and `verticalPolicy` values in the `placementPolicy` property. -![anchor](https://github.com/landarskiy/gridpad_flutter/assets/2251498/1c7e5df7-e311-4d21-b86b-e0304c9f4069) +![anchor](https://github.com/touchlane/gridpad_flutter/assets/2251498/9ec4d525-5450-4aba-a456-3896ce553db4) ## Layout Direction diff --git a/example/lib/components/blueprint.dart b/example/lib/components/blueprint.dart index 9def9cc..c2e06d6 100644 --- a/example/lib/components/blueprint.dart +++ b/example/lib/components/blueprint.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import '../theme.dart'; class BlueprintBox extends StatelessWidget { - const BlueprintBox({Key? key}) : super(key: key); + const BlueprintBox({super.key}); @override Widget build(BuildContext context) { @@ -29,7 +29,7 @@ class BlueprintBox extends StatelessWidget { class ContentBlueprintBox extends StatelessWidget { final String text; - const ContentBlueprintBox({Key? key, this.text = ''}) : super(key: key); + const ContentBlueprintBox({super.key, this.text = ''}); @override Widget build(BuildContext context) { diff --git a/example/lib/components/engineering_calculator_pad.dart b/example/lib/components/engineering_calculator_pad.dart index 4efa029..7a47243 100644 --- a/example/lib/components/engineering_calculator_pad.dart +++ b/example/lib/components/engineering_calculator_pad.dart @@ -5,7 +5,7 @@ import 'package:grid_pad/grid_pad.dart'; import 'pad_button.dart'; class EngineeringCalculatorPad extends StatelessWidget { - const EngineeringCalculatorPad({Key? key}) : super(key: key); + const EngineeringCalculatorPad({super.key}); @override Widget build(BuildContext context) { @@ -19,30 +19,21 @@ class EngineeringCalculatorPad extends StatelessWidget { ), child: GridPad( gridPadCells: GridPadCellsBuilder(rowCount: 5, columnCount: 5) - .rowSize(0, const Fixed(48)) + .rowSize(0, 48.fx()) .build(), children: [ //BG space - Cell( - row: 1, - column: 0, - rowSpan: 4, - columnSpan: 3, - child: DecoratedBox( - decoration: BoxDecoration( - color: padTheme.colors.numBackground, - shape: BoxShape.rectangle, - borderRadius: const BorderRadius.all(Radius.circular(8.0)), - ), - child: Container(), + DecoratedBox( + decoration: BoxDecoration( + color: padTheme.colors.numBackground, + shape: BoxShape.rectangle, + borderRadius: const BorderRadius.all(Radius.circular(8.0)), ), - ), - Cell( - row: 0, - column: 0, - child: _FunctionTheme( - child: SmallTextPadButton('sin', onPressed: () {})), - ), + child: Container(), + ).cell(row: 1, column: 0, rowSpan: 4, columnSpan: 3), + _FunctionTheme( + child: SmallTextPadButton('sin', onPressed: () {}), + ).cell(row: 0, column: 0), _FunctionTheme(child: SmallTextPadButton('cos', onPressed: () {})), _FunctionTheme(child: SmallTextPadButton('log', onPressed: () {})), _FunctionTheme(child: SmallTextPadButton('π', onPressed: () {})), @@ -133,7 +124,7 @@ class EngineeringCalculatorPadTheme { class _FunctionTheme extends StatelessWidget { final Widget child; - const _FunctionTheme({Key? key, required this.child}) : super(key: key); + const _FunctionTheme({required this.child}); @override Widget build(BuildContext context) { @@ -153,7 +144,7 @@ class _FunctionTheme extends StatelessWidget { class _ActionTheme extends StatelessWidget { final Widget child; - const _ActionTheme({Key? key, required this.child}) : super(key: key); + const _ActionTheme({required this.child}); @override Widget build(BuildContext context) { @@ -173,7 +164,7 @@ class _ActionTheme extends StatelessWidget { class _RemoveTheme extends StatelessWidget { final Widget child; - const _RemoveTheme({Key? key, required this.child}) : super(key: key); + const _RemoveTheme({required this.child}); @override Widget build(BuildContext context) { diff --git a/example/lib/components/interactive_pin_pad.dart b/example/lib/components/interactive_pin_pad.dart index bfece1e..d6456a5 100644 --- a/example/lib/components/interactive_pin_pad.dart +++ b/example/lib/components/interactive_pin_pad.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; import 'pin_pad.dart'; class InteractivePinPad extends StatefulWidget { - const InteractivePinPad({Key? key}) : super(key: key); + const InteractivePinPad({super.key}); @override State createState() => _InteractivePinPadState(); diff --git a/example/lib/components/pad_button.dart b/example/lib/components/pad_button.dart index 42b26b3..ad804bc 100644 --- a/example/lib/components/pad_button.dart +++ b/example/lib/components/pad_button.dart @@ -7,9 +7,9 @@ class IconPadButton extends StatelessWidget { const IconPadButton( this.iconData, { - Key? key, + super.key, this.onPressed, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -31,9 +31,9 @@ class LargeTextPadButton extends StatelessWidget { const LargeTextPadButton( this.text, { - Key? key, + super.key, this.onPressed, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -51,9 +51,9 @@ class MediumTextPadButton extends StatelessWidget { const MediumTextPadButton( this.text, { - Key? key, + super.key, this.onPressed, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -71,9 +71,9 @@ class SmallTextPadButton extends StatelessWidget { const SmallTextPadButton( this.text, { - Key? key, + super.key, this.onPressed, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -91,11 +91,11 @@ class TextPadButton extends StatelessWidget { final VoidCallback? onPressed; const TextPadButton({ - Key? key, + super.key, required this.text, this.style, this.onPressed, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -115,8 +115,7 @@ class PadButton extends StatelessWidget { final Widget child; final VoidCallback? onPressed; - const PadButton({Key? key, this.onPressed, required this.child}) - : super(key: key); + const PadButton({super.key, this.onPressed, required this.child}); @override Widget build(BuildContext context) { diff --git a/example/lib/components/pin_pad.dart b/example/lib/components/pin_pad.dart index fed7991..b850267 100644 --- a/example/lib/components/pin_pad.dart +++ b/example/lib/components/pin_pad.dart @@ -7,7 +7,7 @@ import 'pad_button.dart'; class PinPad extends StatelessWidget { final PadActionCallback? callback; - const PinPad({Key? key, this.callback}) : super(key: key); + const PinPad({super.key, this.callback}); @override Widget build(BuildContext context) { @@ -25,14 +25,10 @@ class PinPad extends StatelessWidget { verticalPolicy: VerticalPolicy.bottomTop, ), children: [ - Cell( - row: 3, - column: 1, - child: LargeTextPadButton( - '0', - onPressed: () => callback?.call('0'), - ), - ), + LargeTextPadButton( + '0', + onPressed: () => callback?.call('0'), + ).cell(row: 3, column: 1), PadThemeProvider( theme: PadButtonTheme( colors: PadButtonColors( diff --git a/example/lib/components/simple_calculator_pad.dart b/example/lib/components/simple_calculator_pad.dart index 85b0e94..0f7bc3d 100644 --- a/example/lib/components/simple_calculator_pad.dart +++ b/example/lib/components/simple_calculator_pad.dart @@ -5,7 +5,7 @@ import 'package:grid_pad/grid_pad.dart'; import 'pad_button.dart'; class SimpleCalculatorPad extends StatelessWidget { - const SimpleCalculatorPad({Key? key}) : super(key: key); + const SimpleCalculatorPad({super.key}); @override Widget build(BuildContext context) { @@ -35,21 +35,11 @@ class SimpleCalculatorPad extends StatelessWidget { LargeTextPadButton('1', onPressed: () {}), LargeTextPadButton('2', onPressed: () {}), LargeTextPadButton('3', onPressed: () {}), - Cell.implicit( - rowSpan: 2, - child: _ActionTheme( - child: LargeTextPadButton('=', onPressed: () {}), - ), - ), - Cell( - row: 4, - column: 0, - child: LargeTextPadButton('.', onPressed: () {}), - ), - Cell.implicit( - columnSpan: 2, - child: LargeTextPadButton('0', onPressed: () {}), - ), + _ActionTheme( + child: LargeTextPadButton('=', onPressed: () {}), + ).implicitCell(rowSpan: 2), + LargeTextPadButton('.', onPressed: () {}).cell(row: 4, column: 0), + LargeTextPadButton('0', onPressed: () {}).implicitCell(columnSpan: 2), ], ), ); @@ -115,7 +105,7 @@ extension _ThemeExtension on BuildContext { class _ActionTheme extends StatelessWidget { final Widget child; - const _ActionTheme({Key? key, required this.child}) : super(key: key); + const _ActionTheme({required this.child}); @override Widget build(BuildContext context) { @@ -135,7 +125,7 @@ class _ActionTheme extends StatelessWidget { class _RemoveTheme extends StatelessWidget { final Widget child; - const _RemoveTheme({Key? key, required this.child}) : super(key: key); + const _RemoveTheme({required this.child}); @override Widget build(BuildContext context) { diff --git a/example/lib/components/simple_priority_calculator_pad.dart b/example/lib/components/simple_priority_calculator_pad.dart index fa5627a..bedf7c4 100644 --- a/example/lib/components/simple_priority_calculator_pad.dart +++ b/example/lib/components/simple_priority_calculator_pad.dart @@ -5,7 +5,7 @@ import 'package:grid_pad/grid_pad.dart'; import 'pad_button.dart'; class SimplePriorityCalculatorPad extends StatelessWidget { - const SimplePriorityCalculatorPad({Key? key}) : super(key: key); + const SimplePriorityCalculatorPad({super.key}); @override Widget build(BuildContext context) { @@ -19,22 +19,16 @@ class SimplePriorityCalculatorPad extends StatelessWidget { ), child: GridPad( gridPadCells: GridPadCellsBuilder(rowCount: 5, columnCount: 5) - .rowSize(0, const Fixed(48)) + .rowSize(0, 48.fx()) .build(), children: [ _RemoveTheme(child: MediumTextPadButton('C', onPressed: () {})), - Cell.implicit( - columnSpan: 2, - child: _ActionTheme( - child: MediumTextPadButton('(', onPressed: () {}), - ), - ), - Cell.implicit( - columnSpan: 2, - child: _ActionTheme( - child: MediumTextPadButton(')', onPressed: () {}), - ), - ), + _ActionTheme( + child: MediumTextPadButton('(', onPressed: () {}), + ).implicitCell(columnSpan: 2), + _ActionTheme( + child: MediumTextPadButton(')', onPressed: () {}), + ).implicitCell(columnSpan: 2), LargeTextPadButton('7', onPressed: () {}), LargeTextPadButton('8', onPressed: () {}), LargeTextPadButton('9', onPressed: () {}), @@ -43,38 +37,21 @@ class SimplePriorityCalculatorPad extends StatelessWidget { LargeTextPadButton('4', onPressed: () {}), LargeTextPadButton('5', onPressed: () {}), LargeTextPadButton('6', onPressed: () {}), - Cell.implicit( - rowSpan: 2, - child: _ActionTheme( - child: LargeTextPadButton('-', onPressed: () {}), - ), - ), - Cell.implicit( - rowSpan: 2, - child: _ActionTheme( - child: LargeTextPadButton('+', onPressed: () {}), - ), - ), - Cell( - row: 3, - column: 0, - child: LargeTextPadButton('1', onPressed: () {}), - ), + _ActionTheme( + child: LargeTextPadButton('-', onPressed: () {}), + ).implicitCell(rowSpan: 2), + _ActionTheme( + child: LargeTextPadButton('+', onPressed: () {}), + ).implicitCell(rowSpan: 2), + LargeTextPadButton('1', onPressed: () {}).cell(row: 3, column: 0), LargeTextPadButton('2', onPressed: () {}), LargeTextPadButton('3', onPressed: () {}), - Cell( - row: 4, - column: 0, - child: LargeTextPadButton('0', onPressed: () {}), - ), + LargeTextPadButton('0', onPressed: () {}).cell(row: 4, column: 0), LargeTextPadButton('.', onPressed: () {}), _RemoveTheme(child: IconPadButton(Icons.backspace, onPressed: () {})), - Cell.implicit( - columnSpan: 2, - child: _ActionTheme( - child: LargeTextPadButton('=', onPressed: () {}), - ), - ), + _ActionTheme( + child: LargeTextPadButton('=', onPressed: () {}), + ).implicitCell(columnSpan: 2), ], ), ); @@ -140,7 +117,7 @@ extension _ThemeExtension on BuildContext { class _ActionTheme extends StatelessWidget { final Widget child; - const _ActionTheme({Key? key, required this.child}) : super(key: key); + const _ActionTheme({required this.child}); @override Widget build(BuildContext context) { @@ -160,7 +137,7 @@ class _ActionTheme extends StatelessWidget { class _RemoveTheme extends StatelessWidget { final Widget child; - const _RemoveTheme({Key? key, required this.child}) : super(key: key); + const _RemoveTheme({required this.child}); @override Widget build(BuildContext context) { diff --git a/example/lib/main.dart b/example/lib/main.dart index fc8a33b..427eb4e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -38,7 +38,7 @@ class MyApp extends StatelessWidget { } class HomePage extends StatelessWidget { - const HomePage({Key? key}) : super(key: key); + const HomePage({super.key}); @override Widget build(BuildContext context) { @@ -52,7 +52,7 @@ class HomePage extends StatelessWidget { } class ListOfPads extends StatelessWidget { - const ListOfPads({Key? key}) : super(key: key); + const ListOfPads({super.key}); @override Widget build(BuildContext context) { @@ -84,10 +84,10 @@ class PadCard extends StatelessWidget { final Widget child; const PadCard({ - Key? key, + super.key, required this.ratio, required this.child, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -112,11 +112,11 @@ class BlueprintCard extends StatelessWidget { final Widget child; const BlueprintCard({ - Key? key, + super.key, this.ratio = 1, this.title, required this.child, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -156,10 +156,10 @@ class WeightGrid extends StatelessWidget { final int columnCount; const WeightGrid({ - Key? key, + super.key, required this.rowCount, required this.columnCount, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -176,7 +176,7 @@ class WeightGrid extends StatelessWidget { } class InteractivePinPadCard extends StatelessWidget { - const InteractivePinPadCard({Key? key}) : super(key: key); + const InteractivePinPadCard({super.key}); @override Widget build(BuildContext context) { @@ -202,7 +202,7 @@ class InteractivePinPadCard extends StatelessWidget { } class EngineeringCalculatorPadCard extends StatelessWidget { - const EngineeringCalculatorPadCard({Key? key}) : super(key: key); + const EngineeringCalculatorPadCard({super.key}); @override Widget build(BuildContext context) { @@ -226,7 +226,7 @@ class EngineeringCalculatorPadCard extends StatelessWidget { } class SimplePriorityCalculatorPadCard extends StatelessWidget { - const SimplePriorityCalculatorPadCard({Key? key}) : super(key: key); + const SimplePriorityCalculatorPadCard({super.key}); @override Widget build(BuildContext context) { @@ -248,7 +248,7 @@ class SimplePriorityCalculatorPadCard extends StatelessWidget { } class SimpleCalculatorPadCard extends StatelessWidget { - const SimpleCalculatorPadCard({Key? key}) : super(key: key); + const SimpleCalculatorPadCard({super.key}); @override Widget build(BuildContext context) { @@ -270,7 +270,7 @@ class SimpleCalculatorPadCard extends StatelessWidget { } class SimpleBlueprintCard extends StatelessWidget { - const SimpleBlueprintCard({Key? key}) : super(key: key); + const SimpleBlueprintCard({super.key}); @override Widget build(BuildContext context) { @@ -285,7 +285,7 @@ class SimpleBlueprintCard extends StatelessWidget { } class CustomSizeBlueprintCard extends StatelessWidget { - const CustomSizeBlueprintCard({Key? key}) : super(key: key); + const CustomSizeBlueprintCard({super.key}); @override Widget build(BuildContext context) { @@ -293,8 +293,8 @@ class CustomSizeBlueprintCard extends StatelessWidget { ratio: 1.5, child: GridPad( gridPadCells: GridPadCellsBuilder(rowCount: 3, columnCount: 4) - .rowSize(0, const Weight(2)) - .columnSize(3, const Fixed(30)) + .rowSize(0, 2.wt()) + .columnSize(3, 30.fx()) .build(), children: [for (var i = 0; i < 12; i++) const BlueprintBox()], ), @@ -303,7 +303,7 @@ class CustomSizeBlueprintCard extends StatelessWidget { } class SimpleBlueprintCardWithContent extends StatelessWidget { - const SimpleBlueprintCardWithContent({Key? key}) : super(key: key); + const SimpleBlueprintCardWithContent({super.key}); @override Widget build(BuildContext context) { @@ -331,7 +331,7 @@ class SimpleBlueprintCardWithContent extends StatelessWidget { } class SimpleBlueprintCardWithContentMixOrdering extends StatelessWidget { - const SimpleBlueprintCardWithContentMixOrdering({Key? key}) : super(key: key); + const SimpleBlueprintCardWithContentMixOrdering({super.key}); @override Widget build(BuildContext context) { @@ -367,7 +367,7 @@ class SimpleBlueprintCardWithContentMixOrdering extends StatelessWidget { } class SimpleBlueprintCardWithSpansOverlapped extends StatelessWidget { - const SimpleBlueprintCardWithSpansOverlapped({Key? key}) : super(key: key); + const SimpleBlueprintCardWithSpansOverlapped({super.key}); @override Widget build(BuildContext context) { @@ -411,8 +411,7 @@ class SimpleBlueprintCardPolicy extends StatelessWidget { const SimpleBlueprintCardPolicy( this.mainAxis, this.horizontalPolicy, this.verticalPolicy, - {Key? key}) - : super(key: key); + {super.key}); @override Widget build(BuildContext context) { @@ -448,7 +447,7 @@ class SimpleBlueprintCardPolicy extends StatelessWidget { } class SimpleBlueprintCardPolicyHorizontalSeTb extends StatelessWidget { - const SimpleBlueprintCardPolicyHorizontalSeTb({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyHorizontalSeTb({super.key}); @override Widget build(BuildContext context) { @@ -461,8 +460,7 @@ class SimpleBlueprintCardPolicyHorizontalSeTb extends StatelessWidget { } class SimpleBlueprintCardPolicyHorizontalSeTbRtl extends StatelessWidget { - const SimpleBlueprintCardPolicyHorizontalSeTbRtl({Key? key}) - : super(key: key); + const SimpleBlueprintCardPolicyHorizontalSeTbRtl({super.key}); @override Widget build(BuildContext context) { @@ -474,7 +472,7 @@ class SimpleBlueprintCardPolicyHorizontalSeTbRtl extends StatelessWidget { } class SimpleBlueprintCardPolicyHorizontalEsTb extends StatelessWidget { - const SimpleBlueprintCardPolicyHorizontalEsTb({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyHorizontalEsTb({super.key}); @override Widget build(BuildContext context) { @@ -487,7 +485,7 @@ class SimpleBlueprintCardPolicyHorizontalEsTb extends StatelessWidget { } class SimpleBlueprintCardPolicyHorizontalSeBt extends StatelessWidget { - const SimpleBlueprintCardPolicyHorizontalSeBt({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyHorizontalSeBt({super.key}); @override Widget build(BuildContext context) { @@ -500,7 +498,7 @@ class SimpleBlueprintCardPolicyHorizontalSeBt extends StatelessWidget { } class SimpleBlueprintCardPolicyHorizontalEsBt extends StatelessWidget { - const SimpleBlueprintCardPolicyHorizontalEsBt({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyHorizontalEsBt({super.key}); @override Widget build(BuildContext context) { @@ -513,7 +511,7 @@ class SimpleBlueprintCardPolicyHorizontalEsBt extends StatelessWidget { } class SimpleBlueprintCardPolicyVerticalSeTb extends StatelessWidget { - const SimpleBlueprintCardPolicyVerticalSeTb({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyVerticalSeTb({super.key}); @override Widget build(BuildContext context) { @@ -526,7 +524,7 @@ class SimpleBlueprintCardPolicyVerticalSeTb extends StatelessWidget { } class SimpleBlueprintCardPolicyVerticalEsTb extends StatelessWidget { - const SimpleBlueprintCardPolicyVerticalEsTb({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyVerticalEsTb({super.key}); @override Widget build(BuildContext context) { @@ -539,7 +537,7 @@ class SimpleBlueprintCardPolicyVerticalEsTb extends StatelessWidget { } class SimpleBlueprintCardPolicyVerticalSeBt extends StatelessWidget { - const SimpleBlueprintCardPolicyVerticalSeBt({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyVerticalSeBt({super.key}); @override Widget build(BuildContext context) { @@ -552,7 +550,7 @@ class SimpleBlueprintCardPolicyVerticalSeBt extends StatelessWidget { } class SimpleBlueprintCardPolicyVerticalEsBt extends StatelessWidget { - const SimpleBlueprintCardPolicyVerticalEsBt({Key? key}) : super(key: key); + const SimpleBlueprintCardPolicyVerticalEsBt({super.key}); @override Widget build(BuildContext context) { diff --git a/example/pubspec.lock b/example/pubspec.lock index 5ab9d37..b0a453d 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -37,18 +37,18 @@ packages: dependency: transitive description: name: collection - sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c" + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a url: "https://pub.dev" source: hosted - version: "1.17.1" + version: "1.18.0" cupertino_icons: dependency: "direct main" description: name: cupertino_icons - sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be + sha256: d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d url: "https://pub.dev" source: hosted - version: "1.0.5" + version: "1.0.6" fake_async: dependency: transitive description: @@ -66,10 +66,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c + sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7 url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -81,55 +81,71 @@ packages: path: ".." relative: true source: path - version: "0.9.0" - js: + version: "1.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + url: "https://pub.dev" + source: hosted + version: "10.0.0" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + url: "https://pub.dev" + source: hosted + version: "2.0.1" + leak_tracker_testing: dependency: transitive description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + name: leak_tracker_testing + sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 url: "https://pub.dev" source: hosted - version: "0.6.7" + version: "2.0.1" lints: dependency: transitive description: name: lints - sha256: "6b0206b0bf4f04961fc5438198ccb3a885685cd67d4d4a32cc20ad7f8adbe015" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 url: "https://pub.dev" source: hosted - version: "2.1.0" + version: "3.0.0" matcher: dependency: transitive description: name: matcher - sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb" + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb url: "https://pub.dev" source: hosted - version: "0.12.15" + version: "0.12.16+1" material_color_utilities: dependency: transitive description: name: material_color_utilities - sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.2.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3" + sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04 url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.11.0" path: dependency: transitive description: name: path - sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" url: "https://pub.dev" source: hosted - version: "1.8.3" + version: "1.9.0" sky_engine: dependency: transitive description: flutter @@ -139,26 +155,26 @@ packages: dependency: transitive description: name: source_span - sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" url: "https://pub.dev" source: hosted - version: "1.9.1" + version: "1.10.0" stack_trace: dependency: transitive description: name: stack_trace - sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" url: "https://pub.dev" source: hosted - version: "1.11.0" + version: "1.11.1" stream_channel: dependency: transitive description: name: stream_channel - sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" string_scanner: dependency: transitive description: @@ -179,10 +195,10 @@ packages: dependency: transitive description: name: test_api - sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb + sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "0.6.1" vector_math: dependency: transitive description: @@ -191,6 +207,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + url: "https://pub.dev" + source: hosted + version: "13.0.0" sdks: - dart: ">=3.0.0-417 <4.0.0" + dart: ">=3.2.0-0 <4.0.0" flutter: ">=1.17.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index f7df59e..79582a3 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -6,7 +6,7 @@ publish_to: 'none' version: 1.0.0+1 environment: - sdk: '>=2.18.6 <4.0.0' + sdk: '>=3.0.0 <4.0.0' dependencies: flutter: @@ -20,7 +20,7 @@ dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_lints: ^3.0.1 flutter: diff --git a/lib/grid_pad_cells.dart b/lib/grid_pad_cells.dart index 250b2ca..89c9514 100644 --- a/lib/grid_pad_cells.dart +++ b/lib/grid_pad_cells.dart @@ -151,17 +151,13 @@ extension GridPadCellSizeExtension on Iterable { double totalWeightSize = 0; double totalFixedSize = 0; for (var cellSize in this) { - switch (cellSize.runtimeType) { - case Weight: - totalWeightSize += (cellSize as Weight).size; + switch (cellSize) { + case Weight(): + totalWeightSize += cellSize.size; break; - case Fixed: - totalFixedSize += (cellSize as Fixed).size; + case Fixed(): + totalFixedSize += cellSize.size; break; - default: - throw ArgumentError( - "Unknown type of cell size: ${cellSize.runtimeType}", - ); } } return TotalSize(weight: totalWeightSize, fixed: totalFixedSize); @@ -169,7 +165,7 @@ extension GridPadCellSizeExtension on Iterable { } /// Class describes grid cell size. -abstract class GridPadCellSize {} +sealed class GridPadCellSize {} /// Fixed grid cell size. class Fixed implements GridPadCellSize { @@ -206,12 +202,12 @@ class Weight implements GridPadCellSize { extension FixedExtension on Fixed { /// Create a list with length [count] of fixed cell sizes with size [size]. static List fixedSame(int count, double size) { - return List.generate(count, (index) => Fixed(size)); + return List.generate(count, (index) => size.fx()); } /// Create a list of fixed cell sizes with passed fixed [sizes]. static List fixedSizes(List sizes) { - return sizes.map((size) => Fixed(size)).toList(); + return sizes.map((size) => size.fx()).toList(); } } @@ -219,11 +215,23 @@ extension WeightExtension on Weight { /// Create a list with length [count] of weight cell sizes with /// weight size [size]. static List weightSame(int count, double size) { - return List.generate(count, (index) => Weight(size)); + return List.generate(count, (index) => size.wt()); } /// Create a list of weight cell sizes with passed weight [sizes]. static List weightSizes(List sizes) { - return sizes.map((size) => Weight(size)).toList(); + return sizes.map((size) => size.wt()).toList(); + } +} + +extension CellSizeExtension on num { + /// Create [Fixed] cell size. + Fixed fx() { + return Fixed(toDouble()); + } + + /// Create [Weight] cell size. + Weight wt() { + return Weight(toDouble()); } } diff --git a/lib/grid_pad_widget.dart b/lib/grid_pad_widget.dart index da66e85..c0f49aa 100644 --- a/lib/grid_pad_widget.dart +++ b/lib/grid_pad_widget.dart @@ -70,6 +70,40 @@ class Cell extends ProxyWidget { } } +extension CellExtension on Widget { + /// Wrap the Widget in a Cell + Cell cell({ + Key? key, + required int row, + required int column, + int rowSpan = 1, + int columnSpan = 1, + }) { + return Cell( + key: key, + row: row, + column: column, + rowSpan: rowSpan, + columnSpan: columnSpan, + child: this, + ); + } + + /// Wrap the Widget in a implicit Cell + Cell implicitCell({ + Key? key, + int rowSpan = 1, + int columnSpan = 1, + }) { + return Cell.implicit( + key: key, + rowSpan: rowSpan, + columnSpan: columnSpan, + child: this, + ); + } +} + class _CellElement extends ProxyElement { _CellElement(super.widget); @@ -161,15 +195,11 @@ class _GridPadDelegate extends MultiChildLayoutDelegate { ) { final availableWeight = availableSize - totalSize.fixed; return cellSizes.map((cellSize) { - switch (cellSize.runtimeType) { - case Fixed: - return (cellSize as Fixed).size; - case Weight: - return availableWeight * (cellSize as Weight).size / totalSize.weight; - default: - throw ArgumentError( - "Unknown type of cell size: ${cellSize.runtimeType}", - ); + switch (cellSize) { + case Fixed(): + return cellSize.size; + case Weight(): + return availableWeight * cellSize.size / totalSize.weight; } }).toList(); } @@ -193,15 +223,14 @@ class GridPad extends StatelessWidget { final PlacementStrategy _placementStrategy; GridPad({ - Key? key, + super.key, required this.gridPadCells, required List children, this.placementPolicy = GridPadPlacementPolicy.defaultPolicy, - }) : _placementStrategy = GridPlacementStrategy( + }) : _placementStrategy = GridPlacementStrategy( gridPadCells, placementPolicy, - ), - super(key: key) { + ) { for (var contentCell in children) { final Cell cell; if (contentCell is Cell) { diff --git a/pubspec.yaml b/pubspec.yaml index ad79bdd..ba1522d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,10 @@ name: grid_pad description: GridPad Flutter layout -version: 0.9.0 +version: 1.0.0 repository: https://github.com/touchlane/gridpad_flutter environment: - sdk: '>=2.18.6 <4.0.0' + sdk: '>=3.0.0 <4.0.0' flutter: ">=1.17.0" dependencies: @@ -15,7 +15,7 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter - flutter_lints: ^2.0.0 + flutter_lints: ^3.0.1 test: ^1.21.4 flutter: \ No newline at end of file diff --git a/test/grid_pad_cells_test.dart b/test/grid_pad_cells_test.dart index 11b84ec..697bf29 100644 --- a/test/grid_pad_cells_test.dart +++ b/test/grid_pad_cells_test.dart @@ -28,12 +28,12 @@ import 'package:grid_pad/grid_pad_cells.dart'; void main() { test('Check equals and hashCode for the same GridPadCells', () { final left = GridPadCellsBuilder(rowCount: 2, columnCount: 4) - .columnSize(1, const Weight(2)) - .rowSize(0, const Fixed(24)) + .columnSize(1, 2.wt()) + .rowSize(0, 24.fx()) .build(); final right = GridPadCellsBuilder(rowCount: 2, columnCount: 4) - .columnSize(1, const Weight(2)) - .rowSize(0, const Fixed(24)) + .columnSize(1, 2.wt()) + .rowSize(0, 24.fx()) .build(); expect(left.hashCode, right.hashCode); expect(left, right); @@ -52,11 +52,11 @@ void main() { test('Check internal fields', () { final cells = GridPadCellsBuilder(rowCount: 2, columnCount: 4) - .rowSize(0, const Weight(3)) - .rowSize(1, const Fixed(24)) - .columnSize(0, const Fixed(12)) - .columnSize(1, const Weight(2)) - .columnSize(2, const Fixed(10)) + .rowSize(0, 3.wt()) + .rowSize(1, 24.fx()) + .columnSize(0, 12.fx()) + .columnSize(1, 2.wt()) + .columnSize(2, 10.fx()) .build(); expect(2, cells.rowCount); expect(4, cells.columnCount); @@ -64,13 +64,8 @@ void main() { expect(3, cells.rowsTotalSize.weight); expect(22, cells.columnsTotalSize.fixed); expect(3, cells.columnsTotalSize.weight); - expect([const Weight(3), const Fixed(24)], cells.rowSizes); - expect([ - const Fixed(12), - const Weight(2), - const Fixed(10), - const Weight(1), - ], cells.columnSizes); + expect([3.wt(), 24.fx()], cells.rowSizes); + expect([12.fx(), 2.wt(), 10.fx(), 1.wt()], cells.columnSizes); }); test('Check constructors of GridPadCells', () { @@ -87,28 +82,28 @@ void main() { test('Check GridPadCellsBuilder methods', () { final actual = GridPadCellsBuilder(rowCount: 2, columnCount: 3) - .rowSize(0, const Fixed(30)) - .rowSize(1, const Fixed(30)) - .columnSize(0, const Weight(2)) - .columnSize(1, const Weight(2)) - .columnSize(2, const Weight(2)) + .rowSize(0, 30.fx()) + .rowSize(1, 30.fx()) + .columnSize(0, 2.wt()) + .columnSize(1, 2.wt()) + .columnSize(2, 2.wt()) .build(); final expected = GridPadCellsBuilder(rowCount: 2, columnCount: 3) - .rowsSize(const Fixed(30)) - .columnsSize(const Weight(2)) + .rowsSize(30.fx()) + .columnsSize(2.wt()) .build(); expect(actual, expected); }); test('Check extensions', () { - expect([const Fixed(1), const Fixed(1)], FixedExtension.fixedSame(2, 1)); - expect([const Fixed(1), const Fixed(2)], FixedExtension.fixedSizes([1, 2])); + expect([1.fx(), 1.fx()], FixedExtension.fixedSame(2, 1)); + expect([1.fx(), 2.fx()], FixedExtension.fixedSizes([1, 2])); expect( - [const Weight(0.5), const Weight(0.5)], + [0.5.wt(), 0.5.wt()], WeightExtension.weightSame(2, 0.5), ); expect( - [const Weight(0.5), const Weight(1.5)], + [0.5.wt(), 1.5.wt()], WeightExtension.weightSizes([0.5, 1.5]), ); }); @@ -116,30 +111,17 @@ void main() { test('Check total size calculation', () { expect( const TotalSize(weight: 3, fixed: 22), - [ - const Fixed(12), - const Weight(2), - const Fixed(10), - const Weight(1), - ].calculateTotalSize(), + [12.fx(), 2.wt(), 10.fx(), 1.wt()].calculateTotalSize(), ); }); - test('Check errors. Invalid size options.', () { - expect(() { - Fixed(0); - }, throwsAssertionError); - expect(() { - Weight(0); - }, throwsAssertionError); - expect(() { - [ - const Fixed(1), - const Weight(2), - CustomGriPadCellSize(), - ].calculateTotalSize(); - }, throwsArgumentError); - }); -} + test( + 'Check fx() extension', + () => {expect(12.5.fx(), 12.5.fx())}, + ); -class CustomGriPadCellSize extends GridPadCellSize {} + test( + 'Check wt() extension', + () => {expect(12.5.wt(), 12.5.wt())}, + ); +} diff --git a/test/grid_pad_widget_test.dart b/test/grid_pad_widget_test.dart index b3b368e..f71a35c 100644 --- a/test/grid_pad_widget_test.dart +++ b/test/grid_pad_widget_test.dart @@ -66,8 +66,8 @@ void main() { columnCount: columnCount, ), placementPolicy: placementPolicy, - children: const [ - Cell.implicit(rowSpan: 2, columnSpan: 2, child: Text('0:0')) + children: [ + const Text('0:0').implicitCell(rowSpan: 2, columnSpan: 2), ], ), ); @@ -217,7 +217,7 @@ void main() { class App extends StatelessWidget { final Widget child; - const App({Key? key, required this.child}) : super(key: key); + const App({super.key, required this.child}); @override Widget build(BuildContext context) {