Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
update readme and release v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
soemre committed Oct 22, 2023
1 parent 096a155 commit 1846e2c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ And much more...

Explore the [Example App](https://github.com/emresoysuren/app_manager/tree/main/example) to see practical usage examples.

You can show your support by starring it on GitHub and giving it a like on pub.dev. You can also check out [my other packages on pub.dev](https://pub.dev/publishers/emresoysuren.com/packages).

# Table of Contents
- [Flutter App Manager (app_manager)](#flutter-app-manager-app_manager)
- [Getting Started](#getting-started)
Expand Down Expand Up @@ -362,4 +364,36 @@ If you wish to either "save" or "not save" the current mode locally, you can use
context.core<YourCore>().changeMode(YourCoreModes.yourMode, false); // This mode won't be saved locally and the last saved mode will be used when the app starts again.
```

## Creating Custom Utilities
## Creating Custom Utilities

You can create your own utilities by extending the `AppManagerUtil` class.

```dart
class YourUtil extends AppManagerUtil {}
```

The `AppManagerUtil` requires only one override, which is the `systemMode` getter.

The `systemMode` getter accepts a string to inform the core about the system's current mode. The returned string will be used to search for the corresponding mode in the `modes` map. The core will use a mode if the name of its `mode key` (enum) matches the returned string. If no matches are found, it will use the `default mode` instead.

```dart
class YourUtil extends AppManagerUtil {
@override
String get systemMode => isMode1Active ? "mode1" : "mode2";
}
```

After that, you need to inform the core by calling the `onSystemChange` method of the `AppManagerUtil`. This method informs the core, and after that, the core will use the `systemMode` getter to access the name of the current mode of the system. Before calling the `onSystemChange` method, always use the `isCoreBound` getter to check if it is safe to use `onSystemChange`.

```dart
class YourUtil extends AppManagerUtil {
@override
String get systemMode => isMode1Active ? "mode1" : "mode2";
void didChangePlatformMode() {
if (isCoreBound) onSystemChange!(); // Use it like this
}
}
```

Lastly, you can use your utility to bind with a core by passing it to the `util` parameter of its utility options, as we've discussed in the [Binding Utilities with Cores](#3-binding-utilities-with-cores) chapter.
8 changes: 4 additions & 4 deletions lib/src/utils/app_manager_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ abstract class AppManagerUtil {
String get systemMode;

/// Executed when the class initilizes.
void init();
void init() {}

/// Executed when the class disposes.
void dispose();
void dispose() {}

/// Binds the util with the core.
void bindCore({
Expand All @@ -30,8 +30,8 @@ abstract class AppManagerUtil {
this.onSystemChange = onSystemChange;
}

/// Returns whether the core binded with the util by calling the bindCore or not.
bool get isCoreBinded => onSystemChange != null;
/// Returns whether the core bound with the util by calling the bindCore or not.
bool get isCoreBound => onSystemChange != null;

/// Executed when the current system mode changes.
void Function()? onSystemChange;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/app_manager_util_options.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:app_manager/src/utils/app_manager_util.dart';

class AppManagerUtilOptions<E extends Enum> {
/// The `util` parameter takes an utility and this utility will be binded with the core.
/// The `util` parameter takes an utility and this utility will be bound with the core.
final AppManagerUtil util;

/// The `system` parameter takes enum to use as the `system` mode key.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/lang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppManagerLangUtil extends AppManagerUtil with WidgetsBindingObserver {

@override
void didChangeLocales(List<Locale>? locales) {
if (isCoreBinded) onSystemChange!();
if (isCoreBound) onSystemChange!();
super.didChangeLocales(locales);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AppManagerThemeUtil extends AppManagerUtil with WidgetsBindingObserver {

@override
void didChangePlatformBrightness() {
if (isCoreBinded) onSystemChange!();
if (isCoreBound) onSystemChange!();
super.didChangePlatformBrightness();
}

Expand Down

0 comments on commit 1846e2c

Please sign in to comment.