From 9991c4f93bdfe6166fd903e7e40f6c679ed0590f Mon Sep 17 00:00:00 2001 From: ragokan Date: Sat, 3 Apr 2021 10:54:54 +0300 Subject: [PATCH] more documents, update readme, more extensions --- .idea/libraries/Dart_SDK.xml | 19 ---------- .idea/libraries/KotlinJavaRuntime.xml | 15 -------- .idea/modules.xml | 9 ----- .idea/runConfigurations/main_dart.xml | 6 ---- .idea/workspace.xml | 36 ------------------- README.md | 26 +++++++++++--- lib/bin/extensions/index.dart | 1 + lib/bin/extensions/string_extensions.dart | 4 +++ lib/bin/okito_apps/okito_cupertino_app.dart | 2 ++ lib/bin/okito_apps/okito_material_app.dart | 2 ++ lib/bin/okito_instance.dart | 4 +-- .../modules/watcher_model.dart | 4 +++ .../{null_exception.dart => constants.dart} | 2 ++ lib/bin/okito_utilities/okito_device.dart | 6 ++++ lib/bin/okito_utilities/okito_observer.dart | 5 +-- lib/bin/okito_utilities/okito_routing.dart | 2 +- lib/bin/okito_utilities/okito_widgets.dart | 16 ++++++--- 17 files changed, 61 insertions(+), 98 deletions(-) delete mode 100644 .idea/libraries/Dart_SDK.xml delete mode 100644 .idea/libraries/KotlinJavaRuntime.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations/main_dart.xml delete mode 100644 .idea/workspace.xml create mode 100644 lib/bin/extensions/string_extensions.dart rename lib/bin/okito_utilities/{null_exception.dart => constants.dart} (80%) diff --git a/.idea/libraries/Dart_SDK.xml b/.idea/libraries/Dart_SDK.xml deleted file mode 100644 index 3b605d2..0000000 --- a/.idea/libraries/Dart_SDK.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml deleted file mode 100644 index 2b96ac4..0000000 --- a/.idea/libraries/KotlinJavaRuntime.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 295f0c2..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.idea/runConfigurations/main_dart.xml b/.idea/runConfigurations/main_dart.xml deleted file mode 100644 index aab7b5c..0000000 --- a/.idea/runConfigurations/main_dart.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 5b3388c..0000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/README.md b/README.md index 4d5a6d0..46c9c9b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) @@ -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; @@ -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. @@ -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. @@ -213,6 +230,7 @@ OkitoBuilder( # Extensions ```dart +// Context Extensions context.width; context.height; context.aspectRatio; diff --git a/lib/bin/extensions/index.dart b/lib/bin/extensions/index.dart index 96498f9..1c398f7 100644 --- a/lib/bin/extensions/index.dart +++ b/lib/bin/extensions/index.dart @@ -1 +1,2 @@ export 'context_extensions.dart'; +export 'string_extensions.dart'; diff --git a/lib/bin/extensions/string_extensions.dart b/lib/bin/extensions/string_extensions.dart new file mode 100644 index 0000000..a8f131c --- /dev/null +++ b/lib/bin/extensions/string_extensions.dart @@ -0,0 +1,4 @@ +extension StringExtensions on String { + /// It capitalizes your string. + String get capitalize => this[0].toUpperCase() + substring(1); +} diff --git a/lib/bin/okito_apps/okito_cupertino_app.dart b/lib/bin/okito_apps/okito_cupertino_app.dart index 239652d..6b95330 100644 --- a/lib/bin/okito_apps/okito_cupertino_app.dart +++ b/lib/bin/okito_apps/okito_cupertino_app.dart @@ -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 navigatorKey = Okito.navigatorKey; final List navigatorObservers = [ diff --git a/lib/bin/okito_apps/okito_material_app.dart b/lib/bin/okito_apps/okito_material_app.dart index f793f0c..a7c3470 100644 --- a/lib/bin/okito_apps/okito_material_app.dart +++ b/lib/bin/okito_apps/okito_material_app.dart @@ -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, diff --git a/lib/bin/okito_instance.dart b/lib/bin/okito_instance.dart index 7eef19b..1cd3a30 100644 --- a/lib/bin/okito_instance.dart +++ b/lib/bin/okito_instance.dart @@ -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 @@ -17,7 +17,7 @@ class _Okito with OkitoWidgets, OkitoDevice, OkitoRouting { return navigatorKey.currentContext; } - String? currentRoute; + String? routeName; Object? arguments; } diff --git a/lib/bin/okito_state_management/modules/watcher_model.dart b/lib/bin/okito_state_management/modules/watcher_model.dart index 4c78785..4b207ad 100644 --- a/lib/bin/okito_state_management/modules/watcher_model.dart +++ b/lib/bin/okito_state_management/modules/watcher_model.dart @@ -1,7 +1,11 @@ import '../../../typedefs/callback_types.dart'; class Watcher { + /// 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); diff --git a/lib/bin/okito_utilities/null_exception.dart b/lib/bin/okito_utilities/constants.dart similarity index 80% rename from lib/bin/okito_utilities/null_exception.dart rename to lib/bin/okito_utilities/constants.dart index 2f037a2..ce1487f 100644 --- a/lib/bin/okito_utilities/null_exception.dart +++ b/lib/bin/okito_utilities/constants.dart @@ -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; diff --git a/lib/bin/okito_utilities/okito_device.dart b/lib/bin/okito_utilities/okito_device.dart index 002db95..7ad4f1a 100644 --- a/lib/bin/okito_utilities/okito_device.dart +++ b/lib/bin/okito_utilities/okito_device.dart @@ -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; } diff --git a/lib/bin/okito_utilities/okito_observer.dart b/lib/bin/okito_utilities/okito_observer.dart index 34b7c34..91e7368 100644 --- a/lib/bin/okito_utilities/okito_observer.dart +++ b/lib/bin/okito_utilities/okito_observer.dart @@ -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 diff --git a/lib/bin/okito_utilities/okito_routing.dart b/lib/bin/okito_utilities/okito_routing.dart index ba9f12e..6a8ddda 100644 --- a/lib/bin/okito_utilities/okito_routing.dart +++ b/lib/bin/okito_utilities/okito_routing.dart @@ -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 navigatorKey = GlobalKey(); diff --git a/lib/bin/okito_utilities/okito_widgets.dart b/lib/bin/okito_utilities/okito_widgets.dart index 8d50e96..b810216 100644 --- a/lib/bin/okito_utilities/okito_widgets.dart +++ b/lib/bin/okito_utilities/okito_widgets.dart @@ -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, ),