Skip to content

Commit

Permalink
feat: add fleet_imports package (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold committed Jun 10, 2023
1 parent 4525bb9 commit 8a93e9d
Show file tree
Hide file tree
Showing 17 changed files with 450 additions and 21 deletions.
4 changes: 3 additions & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: fleet
packages:
- packages/**
- packages/fleet
- packages/fleet/example
- packages/fleet_imports
repository: https://github.com/blaugold/fleet

ide:
Expand Down
4 changes: 4 additions & 0 deletions packages/fleet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ for animating with Fleet:
- FleetSliverPadding
- FleetTransform

See the [fleet_imports] package for an way to start using these widgets with
minimal changes to your code.

The following provided widgets are specific to Fleet:

- UniformPadding
Expand All @@ -178,3 +181,4 @@ The following provided widgets are specific to Fleet:
[animationspec]:
https://pub.dev/documentation/fleet/latest/fleet/AnimationSpec-class.html
[animated]: https://pub.dev/documentation/fleet/latest/fleet/Animated-class.html
[fleet_imports]: https://pub.dev/packages/fleet_imports
8 changes: 4 additions & 4 deletions packages/fleet/example/lib/hike_graph.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';
import 'package:fleet_imports/flutter/material.dart';

import 'app.dart';

Expand All @@ -21,7 +21,7 @@ class _PageState extends State<Page> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: const FleetColumn(spacing: 10)([
body: const Column(spacing: 10)([
SegmentedButton<Observation>(
segments: const [
ButtonSegment(
Expand Down Expand Up @@ -78,7 +78,7 @@ class HikeGraph extends StatelessWidget {

return LayoutBuilder(
builder: (context, constraints) {
return FleetRow(
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
spacing: constraints.maxWidth / 120,
)([
Expand Down Expand Up @@ -113,7 +113,7 @@ class GraphCapsule extends StatelessWidget {
@override
Widget build(BuildContext context) {
final relativeRange = range.relativeTo(overallRange);
return FleetContainer(
return Container(
height: height * relativeRange.magnitude,
width: 24,
decoration: ShapeDecoration(
Expand Down
2 changes: 1 addition & 1 deletion packages/fleet/example/lib/interactive_box_fleet.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';
import 'package:fleet_imports/flutter/material.dart';

import 'app.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';
import 'package:fleet_imports/flutter/material.dart';

import 'app.dart';

Expand Down
4 changes: 2 additions & 2 deletions packages/fleet/example/lib/simple_imperative_animation.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';
import 'package:fleet_imports/flutter/material.dart';

import 'app.dart';

Expand Down Expand Up @@ -40,7 +40,7 @@ class _PageState extends State<Page> with AnimatingStateMixin {
@override
Widget build(BuildContext context) {
return Scaffold(
body: const FleetColumn(
body: const Column(
mainAxisAlignment: MainAxisAlignment.center,
spacing: 16,
)([
Expand Down
2 changes: 1 addition & 1 deletion packages/fleet/example/lib/stack.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:fleet/fleet.dart';
import 'package:fleet/modifiers.dart';
import 'package:flutter/material.dart';
import 'package:fleet_imports/flutter/material.dart';

import 'app.dart';

Expand Down
2 changes: 2 additions & 0 deletions packages/fleet/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ dependencies:
cupertino_icons: ^1.0.2
fleet:
path: ..
fleet_imports:
path: ../../fleet_imports
flutter:
sdk: flutter

Expand Down
115 changes: 104 additions & 11 deletions packages/fleet/lib/modifiers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,40 @@ extension BasicModifiers on Widget {

/// Adds [padding] around this widget.
@widgetFactory
Widget padding(EdgeInsetsGeometry padding) {
return FleetPadding(
padding: padding,
child: this,
);
Widget padding(EdgeInsetsGeometry padding, {bool sliver = false}) {
if (sliver) {
return FleetSliverPadding(
padding: padding,
sliver: this,
);
} else {
return FleetPadding(
padding: padding,
child: this,
);
}
}

/// Applies opacity to this widget.
@widgetFactory
Widget opacity(double opacity, {bool alwaysIncludeSemantics = false}) {
return FleetOpacity(
opacity: opacity,
alwaysIncludeSemantics: alwaysIncludeSemantics,
child: this,
);
Widget opacity(
double opacity, {
bool alwaysIncludeSemantics = false,
bool sliver = false,
}) {
if (sliver) {
return FleetSliverOpacity(
opacity: opacity,
alwaysIncludeSemantics: alwaysIncludeSemantics,
sliver: this,
);
} else {
return FleetOpacity(
opacity: opacity,
alwaysIncludeSemantics: alwaysIncludeSemantics,
child: this,
);
}
}

/// Paints the area of this widget.
Expand Down Expand Up @@ -282,4 +301,78 @@ extension BasicModifiers on Widget {
child: this,
);
}

/// Positions this widget within its parent [Stack] widget.
@widgetFactory
Widget position({
double? start,
double? end,
double? left,
double? right,
double? top,
double? bottom,
double? height,
double? width,
bool fill = false,
}) {
assert(
(start == null && end == null) || (left == null && right == null),
'Cannot provide both a start and an end offset and a left and a right '
'offset simultaneously.',
);

if (fill) {
top ??= 0;
bottom ??= 0;
}

if (start != null || end != null) {
if (fill) {
start ??= 0;
end ??= 0;
}
return FleetPositionedDirectional(
start: start,
end: end,
top: top,
bottom: bottom,
height: height,
width: width,
child: this,
);
} else {
if (fill) {
left ??= 0;
right ??= 0;
}
return FleetPositioned(
left: left,
top: top,
right: right,
bottom: bottom,
height: height,
width: width,
child: this,
);
}
}

/// Positions this widget within its parent [Stack] widget using a [Rect].
@widgetFactory
Widget positionFromRect(Rect rect) {
return FleetPositioned.fromRect(
rect: rect,
child: this,
);
}

/// Positions this widget within its parent [Stack] widget using a
/// [RelativeRect].
@widgetFactory
Widget positionFromRelativeRect(RelativeRect rect) {
return FleetPositioned.fromRelativeRect(
rect: rect,
child: this,
);
}
}
Empty file.
18 changes: 18 additions & 0 deletions packages/fleet_imports/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright 2023 Gabriel Terwesten

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 changes: 23 additions & 0 deletions packages/fleet_imports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Alternative imports for Flutter libraries (`widgets`, `material` and
`cupertino`), that substitute widgets for which Fleet provides drop-in
replacements.

By using these imports, you can use Fleet's widgets without having to change
your code.

## Usage

Add a dependency on `fleet_imports` by running `dart pub add fleet_imports` in
your project's root directory.

Then, in your Dart code, replace the imports of `package:flutter` libraries with
the corresponding library from `package:fleet_imports`:

```diff
-import 'package:flutter/material.dart';
+import 'package:fleet_imports/flutter/material.dart';
```

If you are importing a combination of the `widgets`, `material` and `cupertino`
libraries in a file, you have to switch all of them to the corresponding
`fleet_imports` library.
64 changes: 64 additions & 0 deletions packages/fleet_imports/lib/flutter/cupertino.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'package:fleet/fleet.dart';

export 'package:flutter/cupertino.dart'
hide
Align,
Center,
ColoredBox,
Column,
Container,
Flex,
Opacity,
Padding,
Positioned,
PositionedDirectional,
Row,
SizedBox,
SliverOpacity,
SliverPadding,
Transform;

/// Fleet drop-in replacement for [Align].
typedef Align = FleetAlign;

/// Fleet drop-in replacement for [Center].
typedef Center = FleetCenter;

/// Fleet drop-in replacement for [ColoredBox].
typedef ColoredBox = FleetColoredBox;

/// Fleet drop-in replacement for [Column].
typedef Column = FleetColumn;

/// Fleet drop-in replacement for [Container].
typedef Container = FleetContainer;

/// Fleet drop-in replacement for [Flex].
typedef Flex = FleetFlex;

/// Fleet drop-in replacement for [Opacity].
typedef Opacity = FleetOpacity;

/// Fleet drop-in replacement for [Padding].
typedef Padding = FleetPadding;

/// Fleet drop-in replacement for [Positioned].
typedef Positioned = FleetPositioned;

/// Fleet drop-in replacement for [PositionedDirectional].
typedef PositionedDirectional = FleetPositionedDirectional;

/// Fleet drop-in replacement for [Row].
typedef Row = FleetRow;

/// Fleet drop-in replacement for [SizedBox].
typedef SizedBox = FleetSizedBox;

/// Fleet drop-in replacement for [SliverOpacity].
typedef SliverOpacity = FleetSliverOpacity;

/// Fleet drop-in replacement for [SliverPadding].
typedef SliverPadding = FleetSliverPadding;

/// Fleet drop-in replacement for [Transform].
typedef Transform = FleetTransform;
Loading

0 comments on commit 8a93e9d

Please sign in to comment.