flutter_utils_providers 1.0.0
flutter_utils_providers: ^1.0.0 copied to clipboard
A comprehensive Flutter utility package with helpers for validation, data manipulation, file handling, permissions, and more.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter_utils_providers/flutter_utils_providers.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Utils Providers Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Utils Providers Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final TextEditingController _passwordController = TextEditingController();
String _validationResult = '';
NivelSeguridadPassword _securityLevel = NivelSeguridadPassword.medio;
void _validatePassword() {
final isValid = FlutterUtilsProvider.validaPassword(
_securityLevel,
_passwordController.text,
);
setState(() {
_validationResult = isValid
? 'Password is valid for ${_securityLevel.name} security level'
: 'Password does not meet ${_securityLevel.name} security requirements';
});
}
void _testDataManipulation() {
// Example: Deep merge two maps
final map1 = {'name': 'John', 'age': 30};
final map2 = {'age': 31, 'city': 'New York'};
final merged = FlutterUtilsProvider.deepMergeMapInmutable(map1, map2);
// Example: Compare lists
final list1 = [1, 2, 3];
final list2 = [1, 2, 3];
final areEqual = FlutterUtilsProvider.compararListas(list1, list2);
setState(() {
_validationResult = '''
Data Manipulation Examples:
Merged Map: $merged
Lists are equal: $areEqual
''';
});
}
void _testJsonOperations() {
// Example: Validate JSON
final validJson = '{"name": "John", "age": 30}';
final invalidJson = '{name: John}';
final isValid1 = FlutterUtilsProvider.isValidJson(validJson);
final isValid2 = FlutterUtilsProvider.isValidJson(invalidJson);
setState(() {
_validationResult = '''
JSON Validation Examples:
"$validJson" is valid: $isValid1
"$invalidJson" is valid: $isValid2
''';
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const Text(
'Password Validation',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
TextField(
controller: _passwordController,
decoration: const InputDecoration(
labelText: 'Enter password',
border: OutlineInputBorder(),
),
obscureText: true,
),
const SizedBox(height: 16),
DropdownButton<NivelSeguridadPassword>(
value: _securityLevel,
isExpanded: true,
items: NivelSeguridadPassword.values.map((level) {
return DropdownMenuItem(
value: level,
child: Text('Security Level: ${level.name}'),
);
}).toList(),
onChanged: (value) {
setState(() {
_securityLevel = value!;
});
},
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _validatePassword,
child: const Text('Validate Password'),
),
const SizedBox(height: 32),
const Text(
'Other Utilities',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _testDataManipulation,
child: const Text('Test Data Manipulation'),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _testJsonOperations,
child: const Text('Test JSON Operations'),
),
const SizedBox(height: 32),
const Text(
'Result:',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: Text(
_validationResult.isEmpty
? 'No result yet. Try the examples above!'
: _validationResult,
style: const TextStyle(fontSize: 16),
),
),
],
),
),
);
}
@override
void dispose() {
_passwordController.dispose();
super.dispose();
}
}