Skip to content

Commit 7c57e25

Browse files
authored
Merge pull request #9 from aspicas/feature/add-custom-provider-with-widget
Feature/add custom provider with widget
2 parents b7c6bb7 + 16043ea commit 7c57e25

23 files changed

+1594
-230
lines changed

CHANGELOG.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,56 @@
1+
## 1.0.0 (2025-07-17)
2+
3+
* Initial commit ([f0f6dbd](https://github.com/aspicas/flutter_policy_engine/commit/f0f6dbd))
4+
* Merge pull request #1 from aspicas/develop ([59c9c98](https://github.com/aspicas/flutter_policy_engine/commit/59c9c98)), closes [#1](https://github.com/aspicas/flutter_policy_engine/issues/1)
5+
* Merge pull request #2 from aspicas/develop ([6a59b8f](https://github.com/aspicas/flutter_policy_engine/commit/6a59b8f)), closes [#2](https://github.com/aspicas/flutter_policy_engine/issues/2)
6+
* Merge pull request #3 from aspicas/develop ([f8c3e27](https://github.com/aspicas/flutter_policy_engine/commit/f8c3e27)), closes [#3](https://github.com/aspicas/flutter_policy_engine/issues/3)
7+
* Merge pull request #4 from aspicas/feature/add-contributing-file ([023c92e](https://github.com/aspicas/flutter_policy_engine/commit/023c92e)), closes [#4](https://github.com/aspicas/flutter_policy_engine/issues/4)
8+
* Merge pull request #5 from aspicas/develop ([ef7016b](https://github.com/aspicas/flutter_policy_engine/commit/ef7016b)), closes [#5](https://github.com/aspicas/flutter_policy_engine/issues/5)
9+
* Merge pull request #6 from aspicas/feature/update-flutter-version ([1310523](https://github.com/aspicas/flutter_policy_engine/commit/1310523)), closes [#6](https://github.com/aspicas/flutter_policy_engine/issues/6)
10+
* Merge pull request #7 from aspicas/feature/update-flutter-version ([968e891](https://github.com/aspicas/flutter_policy_engine/commit/968e891)), closes [#7](https://github.com/aspicas/flutter_policy_engine/issues/7)
11+
* Merge pull request #8 from aspicas/fix/cicd ([eb4c711](https://github.com/aspicas/flutter_policy_engine/commit/eb4c711)), closes [#8](https://github.com/aspicas/flutter_policy_engine/issues/8)
12+
* chore: initial commit ([a0f2bea](https://github.com/aspicas/flutter_policy_engine/commit/a0f2bea))
13+
* chore: update last commit message ([4d8d0d5](https://github.com/aspicas/flutter_policy_engine/commit/4d8d0d5))
14+
* chore(analysis): update analysis options and linter rules for improved code quality and consistency ([c6ac2ee](https://github.com/aspicas/flutter_policy_engine/commit/c6ac2ee))
15+
* chore(android): update Flutter version to 3.29.3 and add build files for multiple architectures ([f1d5e6d](https://github.com/aspicas/flutter_policy_engine/commit/f1d5e6d))
16+
* chore(ios): update .gitignore and AppDelegate for Swift 5.7 compatibility ([1c5d4d5](https://github.com/aspicas/flutter_policy_engine/commit/1c5d4d5))
17+
* chore(license): add a test placeholder to the LICENSE file ([4eb66ec](https://github.com/aspicas/flutter_policy_engine/commit/4eb66ec))
18+
* chore(license): remove test placeholder from the LICENSE file ([bb31dd7](https://github.com/aspicas/flutter_policy_engine/commit/bb31dd7))
19+
* chore(pubspec): update project description for clarity and add meta dependency ([8e9542b](https://github.com/aspicas/flutter_policy_engine/commit/8e9542b))
20+
* chore(pubspec): update pubspec.yaml for better project visibility ([83515d3](https://github.com/aspicas/flutter_policy_engine/commit/83515d3))
21+
* chore(release): 1.0.0 [skip ci] ([b7c6bb7](https://github.com/aspicas/flutter_policy_engine/commit/b7c6bb7))
22+
* chore(release): configure semantic release with GitHub Actions and update dependencies ([94e1afe](https://github.com/aspicas/flutter_policy_engine/commit/94e1afe))
23+
* chore(release): enhance semantic release configuration with conventional commits support ([03415fb](https://github.com/aspicas/flutter_policy_engine/commit/03415fb))
24+
* chore(release): enhance semantic-release configuration to update pubspec.yaml version ([2e616d2](https://github.com/aspicas/flutter_policy_engine/commit/2e616d2))
25+
* chore(release): simplify release message format by removing CHANGELOG notes ([9aa409d](https://github.com/aspicas/flutter_policy_engine/commit/9aa409d))
26+
* chore(release): streamline changelog configuration and update release message format to skip CI ([b9907c8](https://github.com/aspicas/flutter_policy_engine/commit/b9907c8))
27+
* chore(release): update semantic-release configuration to use POLICY_TOKEN ([6d60fe4](https://github.com/aspicas/flutter_policy_engine/commit/6d60fe4))
28+
* chore(release): update semantic-release to use GH_TOKEN instead of POLICY_TOKEN ([40e650d](https://github.com/aspicas/flutter_policy_engine/commit/40e650d))
29+
* chore(setup): add commit message template configuration ([8a9f2ac](https://github.com/aspicas/flutter_policy_engine/commit/8a9f2ac))
30+
* chore(workflow): enhance commit message validation to cover entire branch ([1171679](https://github.com/aspicas/flutter_policy_engine/commit/1171679))
31+
* fix(android): update fingerprint configuration files ([a80f46f](https://github.com/aspicas/flutter_policy_engine/commit/a80f46f))
32+
* refactor(json): streamline JSON parsing and serialization, replacing deprecated methods ([b05031c](https://github.com/aspicas/flutter_policy_engine/commit/b05031c))
33+
* refactor(logging): enhance LogHandler with detailed documentation and structured logging ([f97aa07](https://github.com/aspicas/flutter_policy_engine/commit/f97aa07))
34+
* refactor(policy): consolidate policy management and evaluation and enhancing PolicyManager ([2ea9d97](https://github.com/aspicas/flutter_policy_engine/commit/2ea9d97))
35+
* refactor(policy): enhance PolicyManager by optimizing JSON parsing with a mapped policy structure ([2c7f0cf](https://github.com/aspicas/flutter_policy_engine/commit/2c7f0cf))
36+
* refactor(tests): enhance type safety and readability in policy test assertions ([4834a66](https://github.com/aspicas/flutter_policy_engine/commit/4834a66))
37+
* refactor(tests): improve readability and maintainability by restructuring policy test cases ([c14be9c](https://github.com/aspicas/flutter_policy_engine/commit/c14be9c))
38+
* feat(example): add example project to test the engine library ([778e376](https://github.com/aspicas/flutter_policy_engine/commit/778e376))
39+
* feat(json): implement JsonHandler for robust JSON conversion and validation utilities ([a1c7993](https://github.com/aspicas/flutter_policy_engine/commit/a1c7993))
40+
* feat(logging): implement LogHandler for structured logging and enhanced debugging capabilities ([4facc99](https://github.com/aspicas/flutter_policy_engine/commit/4facc99))
41+
* feat(logging): introduce LogHandler for structured logging and configurable log levels ([85a5ee8](https://github.com/aspicas/flutter_policy_engine/commit/85a5ee8))
42+
* feat(policy): enhance management by add deep copy functionality and integrating collection package ([7acd0aa](https://github.com/aspicas/flutter_policy_engine/commit/7acd0aa))
43+
* feat(policy): implement core policy management and evaluation interfaces with initial classes ([6287ec5](https://github.com/aspicas/flutter_policy_engine/commit/6287ec5))
44+
* feat(policy): integrate PolicyManager into example app and enhance UI for policy loading ([70aa451](https://github.com/aspicas/flutter_policy_engine/commit/70aa451))
45+
* docs(code-of-conduct): add Contributor Covenant Code of Conduct to establish community standards ([54dc257](https://github.com/aspicas/flutter_policy_engine/commit/54dc257))
46+
* docs(contributing): add contribution guidelines for the flutter_policy_engine project ([f1bdb7f](https://github.com/aspicas/flutter_policy_engine/commit/f1bdb7f))
47+
* docs(issue-templates): add bug report and feature request templates to enhance issue tracking ([e645ffe](https://github.com/aspicas/flutter_policy_engine/commit/e645ffe))
48+
* docs(pr-template): add a pull request template to standardize contributions ([f807e46](https://github.com/aspicas/flutter_policy_engine/commit/f807e46))
49+
* docs(readme): enhance documentation with feature highlights and contribution guidelines ([afd8b7d](https://github.com/aspicas/flutter_policy_engine/commit/afd8b7d))
50+
* docs(templates): add issue templates for bug reports and feature requests to improve issue tracking ([9e2ff7b](https://github.com/aspicas/flutter_policy_engine/commit/9e2ff7b))
51+
* docs(tools): update doc using the setup file ([dc1a378](https://github.com/aspicas/flutter_policy_engine/commit/dc1a378))
52+
* build(setup): add script that installed all the project needs ([6acd4e4](https://github.com/aspicas/flutter_policy_engine/commit/6acd4e4))
53+
154
## 1.0.0 (2025-07-16)
255

356
* chore: initial commit ([a0f2bea](https://github.com/aspicas/flutter_policy_engine/commit/a0f2bea))

example/lib/demo_content.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import 'dart:developer';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_policy_engine/flutter_policy_engine.dart';
5+
6+
class DemoContent extends StatefulWidget {
7+
const DemoContent({super.key});
8+
9+
@override
10+
State<DemoContent> createState() => _DemoContentState();
11+
}
12+
13+
class _DemoContentState extends State<DemoContent> {
14+
String _currentRole = 'guest';
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
return Padding(
19+
padding: const EdgeInsets.all(16.0),
20+
child: Column(
21+
crossAxisAlignment: CrossAxisAlignment.start,
22+
children: [
23+
Text(
24+
'Rol actual: $_currentRole',
25+
style: Theme.of(context).textTheme.headlineSmall,
26+
),
27+
const SizedBox(height: 16),
28+
29+
// Selector de rol
30+
Row(
31+
children: [
32+
_buildRoleButton('guest'),
33+
const SizedBox(width: 8),
34+
_buildRoleButton('user'),
35+
const SizedBox(width: 8),
36+
_buildRoleButton('admin'),
37+
],
38+
),
39+
40+
const SizedBox(height: 32),
41+
42+
// Ejemplos de PolicyWidget
43+
_buildPolicyExample('LoginPage', 'Página de Login'),
44+
_buildPolicyExample('Dashboard', 'Dashboard'),
45+
_buildPolicyExample('UserManagement', 'Gestión de Usuarios'),
46+
_buildPolicyExample('Settings', 'Configuración'),
47+
48+
const SizedBox(height: 32),
49+
],
50+
),
51+
);
52+
}
53+
54+
Widget _buildRoleButton(String role) {
55+
return ElevatedButton(
56+
onPressed: () {
57+
setState(() {
58+
_currentRole = role;
59+
});
60+
},
61+
style: ElevatedButton.styleFrom(
62+
backgroundColor: _currentRole == role ? Colors.blue : Colors.grey,
63+
),
64+
child: Text(role),
65+
);
66+
}
67+
68+
Widget _buildPolicyExample(String content, String displayName) {
69+
return Padding(
70+
padding: const EdgeInsets.only(bottom: 16),
71+
child: Column(
72+
crossAxisAlignment: CrossAxisAlignment.start,
73+
children: [
74+
Text('$displayName:'),
75+
const SizedBox(height: 4),
76+
PolicyWidget(
77+
role: _currentRole,
78+
content: content,
79+
fallback: Card(
80+
color: Colors.red[100],
81+
child: Padding(
82+
padding: const EdgeInsets.all(16),
83+
child: Text('Acceso denegado para $displayName'),
84+
),
85+
),
86+
onAccessDenied: () {
87+
log('Acceso denegado para $_currentRole a $content');
88+
},
89+
child: Card(
90+
color: Colors.green[100],
91+
child: Padding(
92+
padding: const EdgeInsets.all(16),
93+
child: Text('Acceso permitido a $displayName'),
94+
),
95+
),
96+
),
97+
],
98+
),
99+
);
100+
}
101+
}

example/lib/main.dart

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import 'dart:developer';
2-
31
import 'package:flutter/material.dart';
4-
import 'package:flutter_policy_engine/flutter_policy_engine.dart';
2+
import 'package:flutter_policy_engine_example/policy_engine_demo.dart';
53

64
void main() {
75
runApp(const MyApp());
@@ -22,67 +20,3 @@ class MyApp extends StatelessWidget {
2220
);
2321
}
2422
}
25-
26-
class PolicyEngineDemo extends StatefulWidget {
27-
const PolicyEngineDemo({super.key});
28-
29-
@override
30-
State<StatefulWidget> createState() {
31-
return _PolicyEngineDemoState();
32-
}
33-
}
34-
35-
class _PolicyEngineDemoState extends State<PolicyEngineDemo> {
36-
late PolicyManager policyManager;
37-
bool _isInitialized = false;
38-
39-
@override
40-
void initState() {
41-
super.initState();
42-
_initializePolicyManager();
43-
}
44-
45-
Future<void> _initializePolicyManager() async {
46-
policyManager = PolicyManager();
47-
final policies = {
48-
"admin": ["LoginPage", "Dashboard", "UserManagement", "Settings"],
49-
"user": ["LoginPage", "Dashboard"],
50-
"guest": ["LoginPage"]
51-
};
52-
try {
53-
await policyManager.initialize(policies);
54-
setState(() {
55-
_isInitialized = true;
56-
});
57-
} catch (e) {
58-
log(e.toString());
59-
setState(() {
60-
_isInitialized = false;
61-
});
62-
}
63-
}
64-
65-
@override
66-
Widget build(BuildContext context) {
67-
if (!_isInitialized) {
68-
return Scaffold(
69-
appBar: AppBar(
70-
title: const Text('Policy Engine Demo'),
71-
),
72-
body: const Center(
73-
child: Column(
74-
mainAxisAlignment: MainAxisAlignment.center,
75-
children: [
76-
CircularProgressIndicator(),
77-
SizedBox(height: 16),
78-
Text('Loading policies...'),
79-
],
80-
),
81-
),
82-
);
83-
}
84-
return const Center(
85-
child: Text('Policies loaded'),
86-
);
87-
}
88-
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import 'dart:developer';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:flutter_policy_engine/flutter_policy_engine.dart';
5+
import 'package:flutter_policy_engine_example/demo_content.dart';
6+
7+
class PolicyEngineDemo extends StatefulWidget {
8+
const PolicyEngineDemo({super.key});
9+
10+
@override
11+
State<StatefulWidget> createState() {
12+
return _PolicyEngineDemoState();
13+
}
14+
}
15+
16+
class _PolicyEngineDemoState extends State<PolicyEngineDemo> {
17+
late PolicyManager policyManager;
18+
bool _isInitialized = false;
19+
20+
@override
21+
void initState() {
22+
super.initState();
23+
_initializePolicyManager();
24+
}
25+
26+
Future<void> _initializePolicyManager() async {
27+
policyManager = PolicyManager();
28+
final policies = {
29+
"admin": ["LoginPage", "Dashboard", "UserManagement", "Settings"],
30+
"user": ["LoginPage", "Dashboard"],
31+
"guest": ["LoginPage"]
32+
};
33+
try {
34+
await policyManager.initialize(policies);
35+
setState(() {
36+
_isInitialized = true;
37+
});
38+
} catch (e) {
39+
log(e.toString());
40+
setState(() {
41+
_isInitialized = false;
42+
});
43+
}
44+
}
45+
46+
@override
47+
Widget build(BuildContext context) {
48+
if (!_isInitialized) {
49+
return Scaffold(
50+
appBar: AppBar(
51+
title: const Text('Policy Engine Demo'),
52+
),
53+
body: const Center(
54+
child: Column(
55+
mainAxisAlignment: MainAxisAlignment.center,
56+
children: [
57+
CircularProgressIndicator(),
58+
SizedBox(height: 16),
59+
Text('Loading policies...'),
60+
],
61+
),
62+
),
63+
);
64+
}
65+
return PolicyProvider(
66+
policyManager: policyManager,
67+
child: Scaffold(
68+
appBar: AppBar(
69+
title: const Text('Policy Engine Demo'),
70+
),
71+
body: const DemoContent(),
72+
),
73+
);
74+
}
75+
}

lib/flutter_policy_engine.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
library flutter_policy_engine;
22

33
export 'src/core/policy_manager.dart';
4+
export 'src/widgets/policy_widget.dart';
5+
export 'src/core/policy_provider.dart';

0 commit comments

Comments
 (0)