Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adaptive style #244

Merged
merged 15 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions .github/workflows/pub-lish.yml

This file was deleted.

43 changes: 43 additions & 0 deletions examples/adaptive_style_example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
7 changes: 7 additions & 0 deletions examples/adaptive_style_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# adaptive_style_example

### an example app for `adaptive_style`

see more on [pub.dev][pub]

[pub]: https://pub.dev/packages/adaptive_style
28 changes: 28 additions & 0 deletions examples/adaptive_style_example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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 be 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.dev/lints.
#
# 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: false # 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
47 changes: 47 additions & 0 deletions examples/adaptive_style_example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import 'package:adaptive_style/adaptive_style.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApplication());

class MyApplication extends StatelessWidget {
const MyApplication({super.key});

@override
Widget build(context) => ScaleRefProvider(
deviceSizes: const [DeviceSize.iphoneSE],
builder: (context) => const MaterialApp(
home: MyHomePage(),
),
);
}

class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});

@override
Widget build(context) => Material(
child: AdaptiveStackBuilder(
builder: (context, scaleRef, parentSize) => [
AdaptiveAnchorPositioned(
parentSize: parentSize,
data: const AdaptiveAnchorData(
dimension: 100,
edges: AnchorEdges.bottom(),
),
builder: (context, scaleRef, parentSize) => AdaptiveStack(
parentSize: parentSize,
builder: (context, scaleRef, parentSize) => [
const SizedBox.expand(child: ColoredBox(color: Colors.red)),
Center(
child: SizedBox.square(
dimension: 50 * scaleRef.scale.min,
child: const FlutterLogo(),
),
),
],
),
)
],
),
);
}
23 changes: 23 additions & 0 deletions examples/adaptive_style_example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: adaptive_style_example
description: "An example app for adaptive_style."

publish_to: 'none'
version: 1.0.0+1

environment:
sdk: ">=3.3.3 <4.0.0"

dependencies:
flutter:
sdk: flutter
adaptive_style: ^0.0.1
yak_flutter: ^3.0.2


dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.1

flutter:
uses-material-design: true
14 changes: 14 additions & 0 deletions examples/adaptive_style_example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# melos_managed_dependency_overrides: adaptive_style,yak_flutter,yak_result,yak_runner,yak_tween,yak_utils
dependency_overrides:
adaptive_style:
path: ../../packages/adaptive_style
yak_flutter:
path: ../../packages/yak_flutter
yak_result:
path: ../../packages/yak_result
yak_runner:
path: ../../packages/yak_runner
yak_tween:
path: ../../packages/yak_tween
yak_utils:
path: ../../packages/yak_utils
29 changes: 29 additions & 0 deletions packages/adaptive_style/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
3 changes: 3 additions & 0 deletions packages/adaptive_style/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions packages/adaptive_style/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
39 changes: 39 additions & 0 deletions packages/adaptive_style/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

[![melos badge][]][melos]
[![license badge][]][license]


### adaptive_style

a collection of widgets to build scalable UI

# WARNING
this package is an early release and under development
breaking changes are most likely to occur

### how does it work?

- wrap your app in a `ScaleRefProvider`
- provide a list of supported sizes
``` dart
ScaleRefProvider(
deviceSizes: const [DeviceSize.iphoneSE],
///...
```
- use `SizeRef` to get
- the closest supported size
- the scale between the device size and the supported size

### what's included?

- `AdaptiveWidget` the base to build your own custom adaptive widget
- `AdaptiveStack` just like a `Stack` but builds it's children as an `AdaptiveWidget`
- `AdaptiveAnchorPositioned` a `Positioned` that place itself at one of the parent's edges



[melos badge]: https://img.shields.io/badge/maintained%20with-melos-f700ff.svg
[melos]: https://github.com/invertase/melos
[license]: https://opensource.org/licenses/MIT
[license badge]: https://img.shields.io/badge/license-MIT-blue.svg

4 changes: 4 additions & 0 deletions packages/adaptive_style/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
15 changes: 15 additions & 0 deletions packages/adaptive_style/lib/adaptive_style.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
library adaptive_style;

export 'src/adaptive_achor_positioned.dart';
export 'src/scale_mediaquery_widget.dart';
export 'src/adaptive_stack.dart';
export 'src/adaptive_widget_builder.dart';
export 'src/adaptive_widget.dart';
export 'src/device_size.dart';
export 'src/extension.dart';
export 'src/inherited_scale_ref.dart';
export 'src/scale_ref_provider.dart';
export 'src/scale_ref.dart';
export 'src/size_scale.dart';
export 'src/anchor_edges.dart';
export 'src/positioned_data.dart';
39 changes: 39 additions & 0 deletions packages/adaptive_style/lib/src/adaptive_achor_positioned.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/widgets.dart';

import 'adaptive_widget.dart';
import 'adaptive_widget_builder.dart';
import 'positioned_data.dart';

class AdaptiveAnchorPositioned extends AdaptiveWidget {
final AdaptiveAnchorData data;
final AdaptiveWidgetBuilder _builder;

const AdaptiveAnchorPositioned({
super.key,
required AdaptiveWidgetBuilder builder,
required this.data,
required this.parentSize,
}) : _builder = builder;

@override
final Size parentSize;

@override
Widget builder(context, scaleRef, parentSize) {
final positionedData = data.positioned(
parentSize: parentSize,
scale: scaleRef.scale.min,
);
return Positioned(
left: positionedData.edges.left,
right: positionedData.edges.right,
top: positionedData.edges.top,
bottom: positionedData.edges.bottom,
child: _builder(
context,
scaleRef,
positionedData.size,
),
);
}
}
Loading