Skip to content

Commit

Permalink
more documents, update readme, more extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ragokan committed Apr 3, 2021
1 parent a0b41f1 commit 9991c4f
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 98 deletions.
19 changes: 0 additions & 19 deletions .idea/libraries/Dart_SDK.xml

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/libraries/KotlinJavaRuntime.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/runConfigurations/main_dart.xml

This file was deleted.

36 changes: 0 additions & 36 deletions .idea/workspace.xml

This file was deleted.

26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# okito
## The simplest state management solution ever, at least I think so. It depends on nothing, works really fast with minimum code usage.
## Your best coding friend. State management, navigation management, storage management with best usages and with the support of best utilities!
[![pub points](https://badges.bar/okito/pub%20points)](https://pub.dev/packages/okito/score)
[![likes](https://badges.bar/okito/likes)](https://pub.dev/packages/okito/score)
[![popularity](https://badges.bar/okito/popularity)](https://pub.dev/packages/okito/score)
[![pub version](https://img.shields.io/pub/v/okito)](https://pub.dev/packages/okito)
[![GitHub last commit](https://img.shields.io/github/last-commit/ragokan/okito)](https://github.com/ragokan/okito)
### With okito, you don't need to wrap your material app for state management, you don't need any complex libraries and most importantly your don't need context to have a state or update state. For the state management purposes, it is as small as it can be. The aim is reducing the size and dependency usage as much as possible. Basically the state management has only what it needs, nothing more, nothing less!

### For the state management purposes, it is as small as it can be. The aim is reducing the size and dependency usage as much as possible. Basically the state management has only what it needs, nothing more, nothing less!

### Routing, showing snackbars/dialogs/bottommodal without context and from anywhere such as controller with the least amount of code!

### Having access to the local device storage in any device, even in web with same code. Moreover, it is one of the fastest libraries to do it!
 

## Content
Expand All @@ -18,7 +22,7 @@ import 'package:okito/okito.dart'; // You should add this import first.
- [Use Controller](#use-controller)
- [Update Controller](#update-controller)
- [Watch Controller](#watch-controller)
- [Utilities + Routing](#utilities)
- [Utilities + Navigation](#utilities)
- [Local Storage](#local-storage)
- [Extensions](#extensions)
- [Tips](#tips)
Expand All @@ -31,6 +35,17 @@ import 'package:okito/okito.dart'; // You should add this import first.
# State Management

#### Create Controller

Q: What should I do to make it work?
A: Just create a regular class and extend *OkitoController*, if you want to change the state, call update() or setState()

Q: How does these methods notify the state?
A: They have a conversation between themselves, whenever you call these methods, the notifier checks all the builders, if they are watching, they will be re-built. So the scheme is;

Model -> Controller -> Model
View -> Controller -> View
The controller is the root of them.

```dart
class CounterController extends OkitoController {
int count = 0;
Expand Down Expand Up @@ -99,6 +114,8 @@ OkitoBuilder(
```

# Utilities
### Navigation and using widgets without context.

### Firstly, we should wrap our app with Okito or provide Okito
```dart
// Basically, you should add *Okito* to the beginning of your app or provide key/observers manually.
Expand Down Expand Up @@ -145,7 +162,7 @@ Okito.routeName;
# Local Storage
### *OkitoStorage* is a way to save variables to the local storage.
### It works like SharedPereferences but it is synchronous or GetStorage.
#### *OkitoStorage* is blazingly fast because in read operations, it uses memory to get data instead of reading from disk everytime!
#### *OkitoStorage* is blazingly fast because in read operations it uses memory to get data instead of reading from disk everytime!

```dart
// To use, you should init the storage, it is not required for web but required for all other platforms.
Expand Down Expand Up @@ -213,6 +230,7 @@ OkitoBuilder(

# Extensions
```dart
// Context Extensions
context.width;
context.height;
context.aspectRatio;
Expand Down
1 change: 1 addition & 0 deletions lib/bin/extensions/index.dart
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export 'context_extensions.dart';
export 'string_extensions.dart';
4 changes: 4 additions & 0 deletions lib/bin/extensions/string_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extension StringExtensions on String {
/// It capitalizes your string.
String get capitalize => this[0].toUpperCase() + substring(1);
}
2 changes: 2 additions & 0 deletions lib/bin/okito_apps/okito_cupertino_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
import '../okito_instance.dart';
import '../okito_utilities/okito_observer.dart';

/// [OkitoCupertinoApp] is the replacement of [CupertinoApp] to use
/// all of [Okito] features in your app!
class OkitoCupertinoApp extends StatelessWidget {
final GlobalKey<NavigatorState> navigatorKey = Okito.navigatorKey;
final List<NavigatorObserver> navigatorObservers = <NavigatorObserver>[
Expand Down
2 changes: 2 additions & 0 deletions lib/bin/okito_apps/okito_material_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import '../okito_instance.dart';
import '../okito_utilities/okito_observer.dart';

/// [OkitoMaterialApp] is the replacement of [MaterialApp] to use
/// all of [Okito] features in your app!
class OkitoMaterialApp extends StatelessWidget {
OkitoMaterialApp(
{Key? key,
Expand Down
4 changes: 2 additions & 2 deletions lib/bin/okito_instance.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'okito_utilities/constants.dart';
import 'okito_utilities/index.dart';
import 'okito_utilities/null_exception.dart';

class _Okito with OkitoWidgets, OkitoDevice, OkitoRouting {
@override
Expand All @@ -17,7 +17,7 @@ class _Okito with OkitoWidgets, OkitoDevice, OkitoRouting {
return navigatorKey.currentContext;
}

String? currentRoute;
String? routeName;
Object? arguments;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/bin/okito_state_management/modules/watcher_model.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import '../../../typedefs/callback_types.dart';

class Watcher<T> {
/// The OkitoController
final T controller;

/// A callback function that is called whenever the controller calls
/// *update* or *setState*
final VoidCallback callback;

const Watcher(this.controller, this.callback);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// It is the reqular null exception that I throw in routing if the
/// developer didn't use one of below examples.
const String nullException = '''
If you want to use [context] in your app just like this, you have to
use one of these;
Expand Down
6 changes: 6 additions & 0 deletions lib/bin/okito_utilities/okito_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ mixin OkitoDevice {
/// be a power of two. Indeed, it might not even be an integer. For example,
/// the Nexus 6 has a device pixel ratio of 3.5.
double? get devicePixelRatio => context?.devicePixelRatio;

/// Returns true if the device is *android*.
bool get isAndroid => Theme.of(context!).platform == TargetPlatform.android;

/// Returns true if the device is *iOS*.
bool get isIos => Theme.of(context!).platform == TargetPlatform.iOS;
}
5 changes: 3 additions & 2 deletions lib/bin/okito_utilities/okito_observer.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:flutter/material.dart';
import '../../okito.dart';

/// Observer is the way
class OkitoObserver extends NavigatorObserver {
void _setVariables(Route? newRoute) {
Okito.currentRoute = newRoute?.settings.name;
Okito.arguments = newRoute?.settings.arguments;
Okito.routeName = newRoute?.settings.name ?? Okito.context?.routeName;
Okito.arguments = newRoute?.settings.arguments ?? Okito.context?.arguments;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/bin/okito_utilities/okito_routing.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'null_exception.dart';
import 'constants.dart';

mixin OkitoRouting {
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
Expand Down
16 changes: 12 additions & 4 deletions lib/bin/okito_utilities/okito_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ final flutterDialog = showDialog;
mixin OkitoWidgets {
BuildContext? get context;

/// Shows a [SnackBar] across all registered [Scaffold]s.
void showToast(
{required String content, Duration? duration, SnackBarAction? action}) {
/// Shows a [SnackBar] across all registered [Scaffold]s but instead of
/// [SnackBar] widget, you can just give it a string.
void showToast({
required String text,
Duration? duration,
SnackBarAction? action,
TextStyle? textStyle,
}) {
ScaffoldMessenger.of(context!).showSnackBar(
SnackBar(
content: Text(content),
content: Text(
text,
style: textStyle,
),
duration: duration ?? const Duration(seconds: 5),
action: action,
),
Expand Down

0 comments on commit 9991c4f

Please sign in to comment.