Skip to content

Commit

Permalink
Merge pull request #208 from nimblehq/release/1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luongvo authored Jul 5, 2023
2 parents a1f6f90 + 37c1108 commit ff7dd6b
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 58 deletions.
9 changes: 9 additions & 0 deletions bricks/permission_handler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# permission_handler

[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason)

A new brick created with the Mason CLI.

## Description 🚀

This brick has the simple implementation of [permission_handler](https://pub.dev/packages/permission_handler) package.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ abstract class PermissionWrapper {
class PermissionWrapperImpl extends PermissionWrapper {
@override
Future<bool> requestCameraPermission() {
return permission_handler.Permission.camera
.request()
.then((value) => value == permission_handler.PermissionStatus.granted);
return permission_handler.Permission.camera.request().then(
(status) => status == permission_handler.PermissionStatus.granted);
}

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# TODO You can enable the permissions needed here.
# permission, just remove the `#` character in front so it looks like this:
#
# ## dart: PermissionGroup.camera
#'PERMISSION_CAMERA=1'
#
# Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',

## dart: PermissionGroup.calendar
# 'PERMISSION_EVENTS=1',

## dart: PermissionGroup.reminders
# 'PERMISSION_REMINDERS=1',

## dart: PermissionGroup.contacts
# 'PERMISSION_CONTACTS=1',

## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=1',

## dart: PermissionGroup.microphone
# 'PERMISSION_MICROPHONE=1',

## dart: PermissionGroup.speech
# 'PERMISSION_SPEECH_RECOGNIZER=1',

## dart: PermissionGroup.photos
# 'PERMISSION_PHOTOS=1',

## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
# 'PERMISSION_LOCATION=1',

## dart: PermissionGroup.notification
# 'PERMISSION_NOTIFICATIONS=1',

## dart: PermissionGroup.mediaLibrary
# 'PERMISSION_MEDIA_LIBRARY=1',

## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=1',

## dart: PermissionGroup.bluetooth
# 'PERMISSION_BLUETOOTH=1',

## dart: PermissionGroup.appTrackingTransparency
# 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

## dart: PermissionGroup.criticalAlerts
# 'PERMISSION_CRITICAL_ALERTS=1'
]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
permission_handler: ^8.3.0
26 changes: 26 additions & 0 deletions bricks/permission_handler/brick.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: permission_handler
description: A new brick created with the Mason CLI.

# The following defines the version and build number for your brick.
# A version number is three numbers separated by dots, like 1.2.34
# followed by an optional build number (separated by a +).
version: 0.1.0+1

# The following defines the environment for the current brick.
# It includes the version of mason that the brick requires.
environment:
mason: ">=0.1.0-dev.41 <0.1.0"

# Variables specify dynamic values that your brick depends on.
# Zero or more variables can be specified for a given brick.
# Each variable has:
# * a type (string, number, boolean, enum, or array)
# * an optional short description
# * an optional default value
# * an optional list of default values (array only)
# * an optional prompt phrase used when asking for the variable
# * a list of values (enums only)
vars:
# Injected from the root brick by post_gen hook
project_name:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -38,58 +38,7 @@ post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
# TODO You can enable the permissions needed here.
# permission, just remove the `#` character in front so it looks like this:
#
# ## dart: PermissionGroup.camera
#'PERMISSION_CAMERA=1'
#
# Preprocessor definitions can be found in: https://github.com/Baseflow/flutter-permission-handler/blob/master/permission_handler/ios/Classes/PermissionHandlerEnums.h
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',

## dart: PermissionGroup.calendar
# 'PERMISSION_EVENTS=1',

## dart: PermissionGroup.reminders
# 'PERMISSION_REMINDERS=1',

## dart: PermissionGroup.contacts
# 'PERMISSION_CONTACTS=1',

## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=1',

## dart: PermissionGroup.microphone
# 'PERMISSION_MICROPHONE=1',

## dart: PermissionGroup.speech
# 'PERMISSION_SPEECH_RECOGNIZER=1',

## dart: PermissionGroup.photos
# 'PERMISSION_PHOTOS=1',

## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
# 'PERMISSION_LOCATION=1',

## dart: PermissionGroup.notification
# 'PERMISSION_NOTIFICATIONS=1',

## dart: PermissionGroup.mediaLibrary
# 'PERMISSION_MEDIA_LIBRARY=1',

## dart: PermissionGroup.sensors
# 'PERMISSION_SENSORS=1',

## dart: PermissionGroup.bluetooth
# 'PERMISSION_BLUETOOTH=1',

## dart: PermissionGroup.appTrackingTransparency
# 'PERMISSION_APP_TRACKING_TRANSPARENCY=1',

## dart: PermissionGroup.criticalAlerts
# 'PERMISSION_CRITICAL_ALERTS=1'
]
{{#add_permission_handler}}{{{ _Podfile_build_configurations }}}{{/add_permission_handler}}
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies:
intl: ^0.17.0
json_annotation: ^4.5.0
package_info_plus: ^1.4.2
permission_handler: ^8.3.0
{{#add_permission_handler}}{{{ _pubspec_dependencyyaml }}}{{/add_permission_handler}}
retrofit: ^3.0.1+1

dev_dependencies:
Expand Down
5 changes: 5 additions & 0 deletions bricks/template/brick.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ vars:
- kebab
- snake
- pascal
add_permission_handler:
type: boolean
description: Add permission_handler (https://pub.dev/packages/permission_handler) package to the project with some basic setup
default: false
prompt: Add permission_handler package?
2 changes: 2 additions & 0 deletions bricks/template/hooks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.dart_tool
build
6 changes: 6 additions & 0 deletions bricks/template/hooks/bundles/permission_handler_bundle.dart

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

25 changes: 25 additions & 0 deletions bricks/template/hooks/post_gen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'dart:io';

import 'package:mason/mason.dart';

import 'bundles/permission_handler_bundle.dart';

Future<void> run(HookContext context) async {
try {
await generateBricks(context);
} catch (e) {
context.logger.err(e.toString());
}
}

Future<void> generateBricks(HookContext context) async {
if (context.vars['add_permission_handler'] == true) {
await generatePermissionHandlerBrick(context.vars['project_name']);
}
}

Future<void> generatePermissionHandlerBrick(String projectName) async {
final generator = await MasonGenerator.fromBundle(permissionHandlerBundle);
await generator.generate(DirectoryGeneratorTarget(Directory.current),
vars: {'project_name': projectName});
}
33 changes: 33 additions & 0 deletions bricks/template/hooks/pre_gen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:mason/mason.dart';

import 'bundles/permission_handler_bundle.dart';

Future<void> run(HookContext context) async {
try {
final additionalVars = {};
if (context.vars['add_permission_handler'] == true) {
additionalVars.addAll(await addPermissionHandlerVariables());
}
context.vars = {...context.vars, ...additionalVars};
} catch (e) {
context.logger.err(e.toString());
}
}

Future<Map<String, dynamic>> addPermissionHandlerVariables() async {
Map<String, dynamic> vars = {};
final generator = await MasonGenerator.fromBundle(permissionHandlerBundle);
generator.partials.forEach((filePath, content) {
if (filePath.startsWith('{{~ _')) {
// Remove the special characters from the partial files
final formattedName = filePath
.replaceAll('{', '')
.replaceAll('}', '')
.replaceAll('~ ', '')
.replaceAll('.', '')
.trim();
vars.putIfAbsent(formattedName, () => String.fromCharCodes(content));
}
});
return vars;
}
Loading

0 comments on commit ff7dd6b

Please sign in to comment.