Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iconica-development/flutter_hooks_iconica_utilities
A combination of common hooks not included in the flutter_hooks package
https://github.com/iconica-development/flutter_hooks_iconica_utilities
component
Last synced: 2 days ago
JSON representation
A combination of common hooks not included in the flutter_hooks package
- Host: GitHub
- URL: https://github.com/iconica-development/flutter_hooks_iconica_utilities
- Owner: Iconica-Development
- License: bsd-3-clause
- Created: 2024-01-16T16:44:19.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-01T09:20:57.000Z (3 months ago)
- Last Synced: 2024-11-30T04:29:35.821Z (2 months ago)
- Topics: component
- Language: Dart
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.MD
- License: LICENSE
Awesome Lists containing this project
README
# Iconica Flutter Hooks
A list of common hooks used during development not included in flutter_hooks
## Features
### useDelayed
A hook that allows you to run a delayed callback.The callback is managed using a timer and will run after the given delay. The given callback will not be executed if this widget is no longer in the widget tree.
```dart
class DelayedExample extends HookWidget {
const DelayedExample({super.key});@override
Widget build(BuildContext context) {
var state = useState('...waiting');// change the state after 2 seconds
useDelayed(
duration: const Duration(seconds: 2),
callback: () {
state.value = 'Completed';
},
);
return Text(state.value);
}
}
```### usePeriodic
A hook that allows you to run a function on an interval. This uses a timer and does not guarantee exact intervals.Callback will not run if the widget is no longer in the widget tree
```dart
class TickingExample extends HookWidget {
const TickingExample({super.key});@override
Widget build(BuildContext context) {
var state = useState(DateTime.now());
usePeriodic(
duration: const Duration(seconds: 1),
callback: () {
state.value = DateTime.now();
},
);
return Text(state.value.toIso8601String());
}
}
```### useLoadingCallback
A hook that allows you to capture a callback that might return a future and updates the widget when the state of the called callback changes.The result is a callable object that exposes the `isLoading` property to indicate if the most recent call of the function is still executing. The `error` and `stackTrace` values are filled if the most recent call finished with an exception.
You can get an optional callback based on the `isLoading` property through the `optional` property. This will only return the function if `isLoading` is currently false.
This does throttle subsequent calls, preventing another invocation whilst loading is true. You can disable this with the `preventDuplicateCalls` parameter by setting it to true, but subsequent calls will both modify the state making it so that the state is no longer trustworthy.
```dart
class LoadingCallbackExample extends HookWidget {
const LoadingCallbackExample({super.key});@override
Widget build(BuildContext context) {
var onButtonPressed = useLoadingCallback(() async {
debugPrint('executing');
await Future.delayed(const Duration(seconds: 3));
debugPrint('executed');
});return FilledButton(
// the optional returns null when the function is loading and
// returns the function if isLoading returns false
// onButtonPressed is a callable here, so you can also
// provide the onButtonPressed only, but then the FilledButton will not
// realise it is disabled
onPressed: onButtonPressed.optional,
child: SizedBox(
height: 50,
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// isLoading automatically updates if the button is pressed
if (onButtonPressed.isLoading)
const Expanded(
child: Align(
alignment: Alignment.centerLeft,
child: CircularProgressIndicator(),
),
)
else
const Spacer(),
const Text('Press Me'),
const Spacer(),
],
),
),
),
);
}
}
```## Getting started
Add flutter_hooks_iconica_utilities to your pubspec alongside flutter_hooks
```yml
dependencies:
flutter_hooks_iconica_utilities:
git:
url: https://github.com/Iconica-Development/flutter_hooks_iconica_utilities
ref: 1.0.2
flutter_hooks: ^0.20.0
```## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.```dart
const like = 'sample';
```## Issues
Please file any issues, bugs or feature request as an issue on our [GitHub](https://github.com/Iconica-Development/flutter_hooks_iconica_utilities) page. Commercial support is available if you need help with integration with your app or services. You can contact us at [[email protected]](mailto:[email protected]).
## Want to contribute
If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review our [contribution guide](./CONTRIBUTING.md) and send us your [pull request](https://github.com/Iconica-Development/flutter_hooks_iconica_utilities/pulls).
## Author
This `flutter_hooks_iconica_utilities` for Flutter is developed by [Iconica](https://iconica.nl). You can contact us at