Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nank1ro committed Aug 28, 2021
0 parents commit 6ed1339
Show file tree
Hide file tree
Showing 19 changed files with 899 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://www.dartlang.org/guides/libraries/private-files

# Files and directories created by pub
.dart_tool/
.packages
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock

# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/

# Avoid committing generated Javascript files:
*.dart.js
*.info.json # Produced by the --dump-info flag.
*.js # When generated by dart2js. Don't specify *.js if your
# project includes source files written in JavaScript.
*.js_
*.js.deps
*.js.map
19 changes: 19 additions & 0 deletions .idea/libraries/Dart_SDK.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: f4abaa0735eba4dfd8f33f73363911d63931fe03
channel: stable

project_type: package
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Alexandru Mariuti

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.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# awesome_flutter_extensions
Awesome flutter extensions to remove boilerplate
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:very_good_analysis/analysis_options.yaml
19 changes: 19 additions & 0 deletions awesome_flutter_extensions.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/lib" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart Packages" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Flutter Plugins" level="project" />
</component>
</module>
7 changes: 7 additions & 0 deletions lib/awesome_flutter_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
library awesome_flutter_extensions;

export 'src/navigator_ext.dart';
export 'src/sizes_ext.dart';
export 'src/text_styles_ext.dart';
export 'src/theme_colors_ext.dart';
export 'src/themes_ext.dart';
111 changes: 111 additions & 0 deletions lib/src/navigator_ext.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import 'package:flutter/material.dart';

/// Helper extension that allows to use a navigator like:
/// `context.navigator.push(SomePage())`
extension NavigatorX on BuildContext {
/// All the navigator methods
_Navigator get navigator => _Navigator(
canPop: _navigator.canPop,
maybePop: _navigator.maybePop,
pop: _navigator.pop,
popUntil: _navigator.popUntil,
push: _navigator.push,
popAndPushNamed: _navigator.popAndPushNamed,
pushAndRemoveUntil: _navigator.pushAndRemoveUntil,
pushNamed: _navigator.pushNamed,
pushNamedAndRemoveUntil: _navigator.pushNamedAndRemoveUntil,
pushReplacement: _navigator.pushReplacement,
pushReplacementNamed: _navigator.pushReplacementNamed,
removeRoute: _navigator.removeRoute,
removeRouteBelow: _navigator.removeRouteBelow,
replace: _navigator.replace,
replaceRouteBelow: _navigator.replaceRouteBelow,
);

NavigatorState get _navigator => Navigator.of(this);
}

class _Navigator {
_Navigator({
required this.canPop,
required this.maybePop,
required this.pop,
required this.popUntil,
required this.push,
required this.popAndPushNamed,
required this.pushAndRemoveUntil,
required this.pushNamed,
required this.pushNamedAndRemoveUntil,
required this.pushReplacement,
required this.pushReplacementNamed,
required this.removeRoute,
required this.removeRouteBelow,
required this.replace,
required this.replaceRouteBelow,
});

/// See [NavigatorState.canPop].
final bool Function() canPop;

/// See [NavigatorState.maybePop].
final Future<bool> Function<T extends Object?>([T? result]) maybePop;

/// See [NavigatorState.pop].
final void Function<T extends Object?>([T? result]) pop;

/// See [NavigatorState.popUntil].
final void Function(RoutePredicate predicate) popUntil;

/// See [NavigatorState.push].
final Future<T?> Function<T extends Object?>(Route<T> route) push;

/// See [NavigatorState.popAndPushNamed].
final Future<T?> Function<T extends Object?, TO extends Object?>(
String routeName, {
TO? result,
Object? arguments,
}) popAndPushNamed;

/// See [NavigatorState.pushAndRemoveUntil].
final Future<T?> Function<T extends Object?>(
Route<T> newRoute, RoutePredicate predicate) pushAndRemoveUntil;

/// See [NavigatorState.pushNamed].
final Future<T?> Function<T extends Object?>(
String routeName, {
Object? arguments,
}) pushNamed;

/// See [NavigatorState.pushNamedAndRemoveUntil].
final Future<T?> Function<T extends Object?>(
String newRouteName,
RoutePredicate predicate, {
Object? arguments,
}) pushNamedAndRemoveUntil;

/// See [NavigatorState.pushReplacement].
final Future<T?> Function<T extends Object?, TO extends Object?>(
Route<T> newRoute,
{TO? result}) pushReplacement;

/// See [NavigatorState.pushReplacementNamed].
final Future<T?> Function<T extends Object?, TO extends Object?>(
String routeName,
{TO? result,
Object? arguments}) pushReplacementNamed;

/// See [NavigatorState.removeRoute].
final void Function(Route<dynamic> route) removeRoute;

/// See [NavigatorState.removeRouteBelow].
final void Function(Route<dynamic> anchorRoute) removeRouteBelow;

/// See [NavigatorState.replace].
final void Function<T extends Object?>(
{required Route<dynamic> oldRoute, required Route<T> newRoute}) replace;

/// See [NavigatorState.replaceRouteBelow].
final void Function<T extends Object?>(
{required Route<dynamic> anchorRoute,
required Route<T> newRoute}) replaceRouteBelow;
}
65 changes: 65 additions & 0 deletions lib/src/sizes_ext.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';

/// Helper extension that allows to use a size like:
/// `context.sizes.width`
extension Sizes on BuildContext {
/// The list of sizes available to the app
_Sizes get sizes => _Sizes(
width: _width,
height: _height,
padding: _padding,
viewInsets: _viewInsets,
systemGestureInsets: _systemGestureInsets,
viewPadding: _viewPadding,
devicePixelRatio: _devicePixelRatio,
textScaleFactor: _textScaleFactor,
);

MediaQueryData get _mediaQuery => MediaQuery.of(this);

double get _width => _mediaQuery.size.width;
double get _height => _mediaQuery.size.height;
EdgeInsets get _padding => _mediaQuery.padding;
EdgeInsets get _viewInsets => _mediaQuery.viewInsets;
EdgeInsets get _systemGestureInsets => _mediaQuery.systemGestureInsets;
EdgeInsets get _viewPadding => _mediaQuery.viewPadding;
double get _devicePixelRatio => _mediaQuery.devicePixelRatio;
double get _textScaleFactor => _mediaQuery.textScaleFactor;
}

class _Sizes {
_Sizes({
required this.width,
required this.height,
required this.padding,
required this.viewInsets,
required this.systemGestureInsets,
required this.viewPadding,
required this.devicePixelRatio,
required this.textScaleFactor,
});

/// See [Size.width].
final double width;

/// See [Size.height].
final double height;

/// See [MediaQueryData.padding].
final EdgeInsets padding;

/// See [MediaQueryData.viewInsets].
final EdgeInsets viewInsets;

/// See [MediaQueryData.systemGestureInsets].
final EdgeInsets systemGestureInsets;

/// See [MediaQueryData.viewPadding].
final EdgeInsets viewPadding;

/// See [MediaQueryData.devicePixelRatio].
final double devicePixelRatio;

/// See [MediaQueryData.devicePixelRatio].
final double textScaleFactor;
}
Loading

0 comments on commit 6ed1339

Please sign in to comment.