├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── android
├── .gitignore
├── build.gradle
├── gradle.properties
├── settings.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── kotlin
│ └── com
│ └── rarnu
│ └── ktflutter
│ └── KtflutterPlugin.kt
├── example
├── .gitignore
├── .metadata
├── README.md
├── android
│ ├── app
│ │ ├── build.gradle
│ │ └── src
│ │ │ ├── debug
│ │ │ └── AndroidManifest.xml
│ │ │ ├── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── kotlin
│ │ │ │ └── com
│ │ │ │ │ └── example
│ │ │ │ │ └── ktflutter_example
│ │ │ │ │ └── MainActivity.kt
│ │ │ └── res
│ │ │ │ ├── drawable
│ │ │ │ └── launch_background.xml
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ │ └── values
│ │ │ │ └── styles.xml
│ │ │ └── profile
│ │ │ └── AndroidManifest.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ └── settings.gradle
├── ios
│ ├── Flutter
│ │ ├── AppFrameworkInfo.plist
│ │ ├── Debug.xcconfig
│ │ └── Release.xcconfig
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Runner.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ └── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── Runner
│ │ ├── AppDelegate.swift
│ │ ├── Assets.xcassets
│ │ ├── AppIcon.appiconset
│ │ │ ├── Contents.json
│ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ ├── Icon-App-20x20@1x.png
│ │ │ ├── Icon-App-20x20@2x.png
│ │ │ ├── Icon-App-20x20@3x.png
│ │ │ ├── Icon-App-29x29@1x.png
│ │ │ ├── Icon-App-29x29@2x.png
│ │ │ ├── Icon-App-29x29@3x.png
│ │ │ ├── Icon-App-40x40@1x.png
│ │ │ ├── Icon-App-40x40@2x.png
│ │ │ ├── Icon-App-40x40@3x.png
│ │ │ ├── Icon-App-60x60@2x.png
│ │ │ ├── Icon-App-60x60@3x.png
│ │ │ ├── Icon-App-76x76@1x.png
│ │ │ ├── Icon-App-76x76@2x.png
│ │ │ └── Icon-App-83.5x83.5@2x.png
│ │ └── LaunchImage.imageset
│ │ │ ├── Contents.json
│ │ │ ├── LaunchImage.png
│ │ │ ├── LaunchImage@2x.png
│ │ │ ├── LaunchImage@3x.png
│ │ │ └── README.md
│ │ ├── Base.lproj
│ │ ├── LaunchScreen.storyboard
│ │ └── Main.storyboard
│ │ ├── Info.plist
│ │ └── Runner-Bridging-Header.h
├── lib
│ └── main.dart
├── pubspec.lock
├── pubspec.yaml
└── test
│ └── widget_test.dart
├── ios
├── .gitignore
├── Assets
│ └── .gitkeep
├── Classes
│ ├── KtflutterPlugin.h
│ ├── KtflutterPlugin.m
│ └── SwiftKtflutterPlugin.swift
└── ktflutter.podspec
├── ktflutter.iml
├── lib
├── download_extension.dart
├── global_extension.dart
├── http_extension.dart
├── ktflutter.dart
├── list_extension.dart
├── map_extension.dart
├── pair_extension.dart
├── regex_extension.dart
├── route_extension.dart
├── set_extension.dart
├── string_extension.dart
└── toast_extension.dart
├── pubspec.lock
├── pubspec.yaml
└── test
├── ktflutter_http_test.dart
└── ktflutter_test.dart
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | .dart_tool/
3 |
4 | .packages
5 | .pub/
6 |
7 | build/
8 | .vscode/
9 | .idea/
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## 1.0.2
2 |
3 | * re-format code
4 |
5 | ## 1.0.0
6 |
7 | * release
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 CodeMonarch
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # KTFlutter
2 |
3 | A flutter library for lazier programmers.
4 |
5 | ## Getting Started
6 |
7 | Add dependence of ```KTFlutter``` to your project. The last version is ```1.0.2``` .
8 |
9 | ```
10 | dependencies:
11 | ... ...
12 | ktflutter: 1.0.2
13 | ```
14 |
15 | ## Functions
16 |
17 | Functions in the library are ported from kotlin, also included some useful utils like http.
18 |
19 | Here is a list for cognition:
20 |
21 | | Class | Method | Definition | Note |
22 | | :-- | :-- | :-- | :-- |
23 | | _GLOBAL | krun | T krun<T>(T block()) | |
24 | | | krepeat | krepeat(int times, void action(int)) | |
25 | | | kalso | T kalso<T>(T t, void block(T obj)) | |
26 | | | klet | R klet<T, R>(T t, R block(T obj)) | |
27 | | | platform | platform(void block(String s)) | call from native |
28 | | | appVersionCode | appVersionCode(void block(String s)) | call from native |
29 | | | appVersionName | appVersionName(void block(String s)) | call from native |
30 | | | deviceVersion | deviceVersion(void block(String s)) | call from native |
31 | | | deviceModel | deviceModel(void block(String s)) | call from native |
32 | | | deviceId | deviceId(void block(String s)) | call from native |
33 | | | appBundle | appBundle(void block(String s)) | call from native, iOS only |
34 | | | appPackage | appPackage(void block(String s)) | call from native, Android only |
35 | | | deviceDocumentPath | deviceDocumentPath(void block(String path)) | call from native |
36 | | | deviceFilePath | deviceFilePath(void block(String path)) | call from native |
37 | | | deviceCachePath | deviceCachePath(void block(String path)) | call from native |
38 | | | deviceExternalPath | deviceExternalPath(void block(String path)) | call from native, Android only |
39 | | | deviceExternalDocumentPath | deviceExternalDocumentPath(void block(String path)) | call from native, Android only |
40 | | | deviceExternalFilePath | deviceExternalFilePath(void block(String path)) | call from native, Android only |
41 | | | deviceExternalCachePath | deviceExternalCachePath(void block(String path)) | call from native, Android only |
42 | | | deviceObbPath | deviceObbPath(void block(String path)) | call from native, Android only |
43 | | _ROUTE | route | route<T>(String name, dynamic arguments, void block(T obj)) | |
44 | | | routeList | routeList<T>(String name, dynamic arguments, void block(List<T> list)) | |
45 | | | routeMap | routeMap<K, V>(String name, dynamic arguments, void block(Map<K, V> map)) | |
46 | | | routeObj | routeObj<T>(String name, dynamic arguments, T parse(dynamic p), void block(T obj)) | |
47 | | | routeObjList | routeObjList<T>(String name, dynamic arguments, T parse(dynamic p), void block(List<T> list)) | |
48 | | | routeObjMap | routeObjMap<K, V>(String name, dynamic arguments, V parse(dynamic p), void block(Map<K, V> map)) | |
49 | | HttpMethod | | GET, HEAD, POST, PUT, DELETE | |
50 | | HttpResponse | | | |
51 | | HttpError | | | |
52 | | _HTTP | http | Future<HttpResponse> http(String url, HttpMethod method, {Map<String, String> param,String mimeType='application/json', String body, Map<String, String> postParam, Map<String, String> fileParam, Map<String, String> headers, int timeout=15}) | |
53 | | | httpGet | Future<HttpResponse> httpGet(String url, {Map<String, String> param, Map<String, String> headers}) | |
54 | | | httpPost | Future<HttpResponse> httpPost(String url, {Map<String, String> param, String body, Map<String, String> headers}) | |
55 | | DownloadState | | Start, Progress, Complete, Error | |
56 | | DownloadCallback | | void Function(DownloadState state, int position, int filesize, String error) | |
57 | | _ DOWNLOAD| download | Future<bool> download(String url, String localFile, DownloadCallback callback) | |
58 | | _TOAST | toast | toast(BuildContext context, String message, [int duration = 2]) | |
59 | | KFPair | toList | KFList<T> toList() | |
60 | | KFString | stringOf | KFString stringOf(String str) | |
61 | | | also | KFString also(void block(KFString s)) | |
62 | | | let | R let<R>(R block(KFString s)) | |
63 | | | takeIf | KFString takeIf(bool block(KFString s)) | |
64 | | | takeUnless | KFString takeUnless(bool block(KFString s)) | |
65 | | | substringBefore | KFString substringBefore(Pattern pattern) | |
66 | | | substringAfter | KFString substringAfter(Pattern pattern) | |
67 | | | substringBeforeLast | KFString substringBeforeLast(Pattern pattern) | |
68 | | | substringAfterLast | KFString substringAfterLast(Pattern pattern) | |
69 | | | removeRange | KFString removeRange(int startIdx, int endIdx) | |
70 | | | removePrefix | KFString removePrefix(Pattern pattern) | |
71 | | | removeSuffix | KFString removeSuffix(Pattern pattern) | |
72 | | | removeSurrounding | KFString removeSurrounding(Pattern pattern) | |
73 | | | replaceBefore | KFString replaceBefore(Pattern pattern, Object replacement) | Object can be String/KFString |
74 | | | replaceAfter | KFString replaceAfter(Pattern pattern, Object replacement) | Object can be String/KFString |
75 | | | replaceAfterLast | KFString replaceAfterLast(Pattern pattern, Object replacement) | Object can be String/KFString |
76 | | | replaceBeforeLast | KFString replaceBeforeLast(Pattern pattern, Object replacement) | Object can be String/KFString |
77 | | | lines | KFList<KFString> lines() | |
78 | | | drop | KFString drop(int n) | |
79 | | | dropLast | KFString dropLast(int n) | |
80 | | | filter | KFString filter(bool block(KFString str)) | |
81 | | | filterIndexed | KFString filterIndexed(bool block(int idx, KFString str)) | |
82 | | | filterNot | KFString filterNot(bool block(KFString str)) | |
83 | | | reversed | KFString reversed() | |
84 | | | toList | KFList<KFString> toList() | |
85 | | | map | KFList<T> map<T>(T block(KFString s)) | |
86 | | | mapIndexed | KFList<T> mapIndexed<T>(T block(int idx, KFString s)) | |
87 | | | forEach | forEach(void action(KFString s)) | |
88 | | | forEachIndexed | forEachIndexed(void action(int idx, KFString s)) | |
89 | | | reduce | KFString reduce(KFString oper(KFString acc, KFString s)) | |
90 | | | reduceIndexed | KFString reduceIndexed(KFString oper(int idx, KFString acc, KFString s)) | |
91 | | | toInt | int toInt() | |
92 | | | toDouble | double toDouble() | |
93 | | | toBool | bool toBool() | |
94 | | | base64encode | KFString base64encode() | |
95 | | | base64decode | KFString base64decode() | |
96 | | | toIntList | KFList<int> toIntList() | |
97 | | | lastPathPart | KFString lastPathPart() | |
98 | | | getPathDirectory | KFString getPathDirectory() | |
99 | | | toJsonEncoded | KFString toJsonEncoded() | |
100 | | | toTitleUpperCase | KFString toTitleUpperCase() | |
101 | | | appendPathPart | KFString appendPathPart(Object part) | Object can be String/KFString |
102 | | | extension | KFString extension() | |
103 | | | replaceTag | KFString replaceTag(String tag, KFString block()) | |
104 | | | skipEmptyLine | KFString skipEmptyLine() | |
105 | | | toPair | KFPair<KFString, KFString> toPair() | |
106 | | | save | save(File f) | |
107 | | | asFileWriteText | File asFileWriteText(Object s) | Object can be String/KFString |
108 | | | asFileReadText | KFString asFileReadText() | |
109 | | | asFileMkdirs | asFileMkdirs() | |
110 | | | asFile | File asFile() | |
111 | | KFList<E> | listOf | KFList<E> listOf<E>(Iterable<E> list) | |
112 | | | toFlutterList | List<E< toFlutterList() | |
113 | | | also | KFList<E> also(void block(KFList<E> list)) | |
114 | | | let | R let<R>(R block(KFList<E> list)) | |
115 | | | takeIf | KFList<E> takeIf(bool block(KFList<E> list)) | |
116 | | | takeUnless | KFList<E> takeUnless(bool block(KFList<E> list)) | |
117 | | | find | E find(bool block(E obj)) | |
118 | | | findLast | E findLast(bool block(E obj)) | |
119 | | | indexOfFirst | int indexOfFirst(bool block(E obj)) | |
120 | | | indexOfLast | int indexOfLast(bool block(E obj)) | |
121 | | | drop | KFList<E> drop(int n) | |
122 | | | dropLast | KFList<E> dropLast(int n) | |
123 | | | filter | KFList<E> filter(bool block(E obj)) | |
124 | | | filterIndexed | KFList<E> filterIndexed(bool block(int idx, E obj)) | |
125 | | | filterNot | KFList<E> filterNot(bool block(E obj)) | |
126 | | | slice | KFList<E> slice(int startIdx, int endIdx) | |
127 | | | sortBy | KFList<E> sortBy(int block(E first, E second)) | |
128 | | | sortByDescending | KFList<E> sortByDescending(int block(E first, E second)) | |
129 | | | map | KFList<T> map<T>(T block(E obj)) | overrided |
130 | | | mapIndexed | KFList<T> mapIndexed<T>(T block(int idx, E obj)) | |
131 | | | distinct | KFList<E> distinct() | |
132 | | | distinctBy | KFList<E> distinctBy<K>(K block(E obj)) | |
133 | | | all | bool all(bool block(E obj)) | |
134 | | | any | bool any(bool block(E obj)) | |
135 | | | count | int count(bool block(E obj)) | |
136 | | | forEachIndexed | forEachIndexed(void action(int index, E element)) | |
137 | | | none | bool none(bool block(E obj)) | |
138 | | | reduceIndexed | E reduceIndexed(E oper(int idx, E acc, E s)) | |
139 | | | minus | minus(Object obj) | Object can be List/KFList |
140 | | | joinToString | KFString joinToString([String sep = ","]) | |
141 | | | toStringList | KFList<String> toStringList() | |
142 | | | toMap | KFMap<K, V> toMap<K, V>() | |
143 | | | mapTo | C mapTo<R, C extends List<R>>(C dest, R block(E obj)) | |
144 | | | mapIndexedTo | C mapIndexedTo<R, C extends List<R>>(C dest, R block(int idx, E obj)) | |
145 | | | filterTo | C filterTo<C extends List<E>>(C dest, bool block(E obj)) | |
146 | | | filterIndexedTo | C filterIndexedTo<C extends List<E>>(C dest, bool block(int idx, E obj)) | |
147 | | | filterNotTo | C filterNotTo<C extends List<E>>(C dest, bool block(E obj)) | |
148 | | KFSet<E> | setOf | KFSet<E> setOf<E>(Iterable<E> set) | |
149 | | | also | KFSet<E> also(void block(KFSet<E> list)) | |
150 | | | let | R let<R>(R block(KFSet<E> list)) | |
151 | | | takeIf | KFSet<E> takeIf(bool block(KFSet<E> list)) | |
152 | | | takeUnless | KFSet<E> takeUnless(bool block(KFSet<E> list)) | |
153 | | | find | E find(bool block(E obj)) | |
154 | | | findLast | E findLast(bool block(E obj)) | |
155 | | | indexOfFirst | int indexOfFirst(bool block(E obj)) | |
156 | | | indexOfLast | int indexOfLast(bool block(E obj)) | |
157 | | | drop | KFSet<E> drop(int n) | |
158 | | | dropLast | KFSet<E> dropLast(int n) | |
159 | | | filter | KFSet<E> filter(bool block(E obj)) | |
160 | | | filterIndexed | KFSet<E> filterIndexed(bool block(int idx, E obj)) | |
161 | | | filterNot | KFSet<E> filterNot(bool block(E obj)) | |
162 | | | slice | KFSet<E> slice(int startIdx, int endIdx) | |
163 | | | sortBy | KFSet<E> sortBy(int block(E first, E second)) | |
164 | | | sortByDescending | KFSet<E> sortByDescending(int block(E first, E second)) | |
165 | | | map | KFSet<T> map<T>(T block(E obj)) | overrided |
166 | | | mapIndexed | KFSet<T> mapIndexed<T>(T block(int idx, E obj)) | |
167 | | | distinct | KFSet<E> distinct() | |
168 | | | distinctBy | KFSet<E> distinctBy<K>(K block(E obj)) | |
169 | | | all | bool all(bool block(E obj)) | |
170 | | | any | bool any(bool block(E obj)) | |
171 | | | count | int count(bool block(E obj)) | |
172 | | | forEachIndexed | forEachIndexed(void action(int index, E element)) | |
173 | | | none | bool none(bool block(E obj)) | |
174 | | | reduceIndexed | E reduceIndexed(E oper(int idx, E acc, E s)) | |
175 | | | minus | minus(Object obj) | |
176 | | | joinToString | KFString joinToString([String sep = ","]) | |
177 | | | toStringList | KFSet<String> toStringList() | |
178 | | | toMap | KFMap<K, V> toMap<K, V>() | |
179 | | | mapTo | C mapTo<R, C extends Set<R>>(C dest, R block(E obj)) | |
180 | | | mapIndexedTo | C mapIndexedTo<R, C extends Set<R>>(C dest, R block(int idx, E obj)) | |
181 | | | filterTo | C filterTo<C extends Set<E>>(C dest, bool block(E obj)) | |
182 | | | filterIndexedTo | C filterIndexedTo<C extends Set<E>>(C dest, bool block(int idx, E obj)) | |
183 | | | filterNotTo | C filterNotTo<C extends Set<E>>(C dest, bool block(E obj)) | |
184 | | KFMap<K, V> | mapOf | KFMap<K, V> mapOf<K, V6gt;(Map<K, V> map) | |
185 | | | also | KFMap<K, V> also(void block(KFMap<K, V> map)) | |
186 | | | let | R let<R>(R block(KFMap<K, V> list)) | |
187 | | | takeIf | KFMap<K, V> takeIf(bool block(KFMap<K, V> list)) | |
188 | | | takeUnless | KFMap<K, V> takeUnless(bool block(KFMap<K, V> list)) | |
189 | | | toList | KFList<KFPair<K, V>> toList() | |
190 | | | mapToList | KFList<R> mapToList<R>(R block(MapEntry<K, V> e))| |
191 | | | forEachEntry | forEachEntry(void block(MapEntry<K, V> e)) | |
192 | | | all | bool all(bool block(MapEntry<K, V> e)) | |
193 | | | any | bool any(bool block(MapEntry<K, V> e)) | |
194 | | | count | int count(bool block(MapEntry<K, V> e)) | |
195 | | | none | bool none(bool block(MapEntry<K, V> e)) | |
196 | | | filterKeys | KFMap<K, V> filterKeys(bool block(K k)) | |
197 | | | filterValues | KFMap<K, V> filterValues(bool block(V v)) | |
198 | | | filter | KFMap<K, V> filter(bool block(MapEntry<K, V> e)) | |
199 | | | filterNot | KFMap<K, V> filterNot(bool block(MapEntry<K, V> e)) | |
200 | | | add | add(Object obj) | Object can be Map/KFMap |
201 | | | minus | minus(Object obj) | Object can be Map/KFMap |
202 | | | filterTo | KFMap<K, V> filterTo<M extends Map<K, V>>(M dest, bool block(MapEntry<K, V> e)) | |
203 | | | filterNotTo | KFMap<K, V> filterNotTo<M extends Map<K, V>>(M dest, bool block(MapEntry<K, V> e)) | |
204 | | | filterKeysTo | KFMap<K, V> filterKeysTo<M extends Map<K, V>>(M dest, bool block(K k)) | |
205 | | | filterValuesTo | KFMap<K, V> filterValuesTo<M extends Map<K, V>>(M dest, bool block(V v)) | |
206 | | | mapTo | KFMap<K2, V2> mapTo<K2, V2, C extends Map<K2, V2>>(C dest, MapEntry<K2, V2> block(MapEntry<K, V> e)) | |
207 | | | mapToListTo | KFList<R> mapToListTo<R, C extends List<R>>(C dest, R block(MapEntry<K, V> e)) | |
208 | | | mapKeysTo | KFMap<K2, V2> mapKeysTo<K2, V2, C extends Map<K2, V2>>(C dest, MapEntry<K2, V2> block(K k)) | |
209 | | | mapKeysToListTo | KFList<R> mapKeysToListTo<R, C extends List<R>>(C dest, R block(K k)) | |
210 | | | mapValuesTo | KFMap<K2, V2> mapValuesTo<K2, V2, C extends Map<K2, V2>>(C dest, MapEntry<K2, V2> block(V v)) | |
211 | | | mapValuesToListTo | KFList<R> mapValuesToListTo<R, C extends List<R>>(C dest, R block(V v)) | |
212 | | _REGEXP | regexMatch | bool regexMatch(String str, String regex) | |
213 | | | isStringReg | bool isStringReg(String str, int type) | |
214 | | | isNumberReg | bool isNumberReg(String str, int type) | |
215 | | | isEmail | bool isEmail(String str) | |
216 | | | isPhoneNumber | bool isPhoneNumber(String str) | |
217 | | | isCellPhoneNumber | bool isCellPhoneNumber(String str) | |
218 | | | isChinesePhoneNumber | bool isChinesePhoneNumber(String str) | |
219 | | | isIdCardNumber | bool isIdCardNumber(String str) | |
220 | | | isShortIdCardNumber | bool isShortIdCardNumber(String str) | |
221 | | | isUrl | bool isUrl(String str) | |
222 | | | isDomain | bool isDomain(String str) | |
223 | | | isValidAccount | bool isValidAccount(String str) | |
224 | | | isValidPassword | bool isValidPassword(String str) | |
225 | | | isStrongPassword | bool isStrongPassword(String str) | |
226 | | | isDate | bool isDate(String str) | |
227 | | | isValidXml | bool isValidXml(String str) | |
228 | | | isBlankLine | bool isBlankLine(String str) | |
229 | | | isValidHtml | bool isValidHtml(String str) | |
230 | | | isValidQQNumber | bool isValidQQNumber(String str) | |
231 | | | isValidPostCode | bool isValidPostCode(String str) | |
232 | | | isValidIPAddress | bool isValidIPAddress(String str) | |
233 | | KMixin<T> | also | T also(void block(T obj)) | |
234 | | | let | R let<R>(R block(T obj)) | |
235 | | | takeIf | T takeIf(bool block(T obj)) | |
236 | | | takeUnless | T takeUnless(bool block(T obj)) | |
237 | | | | | |
238 |
239 | ## example
240 |
241 | You may visit ```example``` project for more about ```KTFlutter```
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | group 'com.example.ktflutter'
2 | version '1.0-SNAPSHOT'
3 |
4 | buildscript {
5 | ext.kotlin_version = '1.2.71'
6 | repositories {
7 | google()
8 | jcenter()
9 | }
10 |
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:3.2.1'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | }
15 | }
16 |
17 | rootProject.allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | }
22 | }
23 |
24 | apply plugin: 'com.android.library'
25 | apply plugin: 'kotlin-android'
26 |
27 | android {
28 | compileSdkVersion 28
29 |
30 | sourceSets {
31 | main.java.srcDirs += 'src/main/kotlin'
32 | }
33 | defaultConfig {
34 | minSdkVersion 16
35 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
36 | }
37 | lintOptions {
38 | disable 'InvalidPackage'
39 | }
40 | }
41 |
42 | dependencies {
43 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
44 | }
45 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 |
3 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'ktflutter'
2 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/android/src/main/kotlin/com/rarnu/ktflutter/KtflutterPlugin.kt:
--------------------------------------------------------------------------------
1 | @file:Suppress("DEPRECATION")
2 |
3 | package com.rarnu.ktflutter
4 |
5 | import android.content.Context
6 | import android.os.Build
7 | import android.os.Environment
8 | import android.provider.Settings
9 | import io.flutter.plugin.common.MethodChannel
10 | import io.flutter.plugin.common.PluginRegistry
11 | import java.io.File
12 |
13 | fun nativeRouting(block: KtflutterPlugin.() -> Unit) {
14 | block(KtflutterPlugin)
15 | }
16 |
17 | /*
18 | deviceDocumentPath(void block(String path)) async => block(await posix.invokeMethod("device_document_path", {}));
19 | deviceFilePath(void block(String path)) async => block(await posix.invokeMethod("device_file_path", {}));
20 | deviceCachePath(void block(String path)) async => block(await posix.invokeMethod("device_cache_path", {}));
21 |
22 | // android only
23 | deviceExternalPath(void block(String path)) => platform((p) async {
24 | block(p == "Android" ? (await posix.invokeMethod("device_external_path", {})) : "");
25 | });
26 |
27 | */
28 |
29 | object KtflutterPlugin {
30 | private const val channelName = "com.rarnu.flutter/routing"
31 | private val channelList = mutableMapOf) -> Any?>()
32 |
33 | @JvmStatic
34 | fun registerWith(registrar: PluginRegistry.Registrar) {
35 | MethodChannel(registrar.messenger(), channelName).setMethodCallHandler { call, result ->
36 | when(call.method) {
37 | "platform" -> result.success("Android")
38 | "app_version_code" -> result.success(with(registrar.context()) { packageManager.getPackageInfo(packageName, 0).versionCode.toString() })
39 | "app_version_name" -> result.success(with(registrar.context()) { packageManager.getPackageInfo(packageName, 0).versionName })
40 | "app_package" -> result.success(registrar.context().packageName)
41 | "device_version" -> result.success(Build.VERSION.SDK_INT.toString())
42 | "device_model" -> result.success(Build.MODEL)
43 | "device_id" -> result.success(Settings.Secure.getString(registrar.context().contentResolver, Settings.Secure.ANDROID_ID))
44 | // paths
45 | "device_document_path" -> result.success(registrar.context().filesDir.absolutePath.substringBeforeLast("/"))
46 | "device_file_path"-> result.success(registrar.context().filesDir.absolutePath.also { with(File(it)) { if (!exists()) mkdirs() } })
47 | "device_cache_path" -> result.success(registrar.context().cacheDir.absolutePath.also { with(File(it)) { if (!exists()) mkdirs() } })
48 | // android only paths
49 | "device_external_path" -> result.success(Environment.getExternalStorageDirectory().absolutePath)
50 | "device_external_document_path" -> result.success(registrar.context().getExternalFilesDir("")?.absolutePath?.substringBeforeLast("/"))
51 | "device_external_file_path" -> result.success(registrar.context().getExternalFilesDir("")?.absolutePath.also { with(File(it)) { if (!exists()) mkdirs() } })
52 | "device_external_cache_path" -> result.success(registrar.context().externalCacheDir?.absolutePath.also { with(File(it)) { if (!exists()) mkdirs() } })
53 | "device_obb_path" -> result.success(registrar.context().obbDir?.absolutePath.also { with(File(it)) { if (!exists()) mkdirs() } })
54 |
55 | else -> {
56 | val m = channelList[call.method]
57 | if (m != null) {
58 | val ret = m(registrar.context(), call.arguments as Map)
59 | result.success(if (ret is Unit) null else ret)
60 | } else {
61 | result.success(null)
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
68 | fun route(name: String, block:(ctx: Context, params: Map) -> Any?) {
69 | channelList[name] = block
70 | }
71 | fun routeList(name: String, block:(ctx: Context, params: Map) -> List?) {
72 | channelList[name] = block
73 | }
74 | fun routeMap(name: String, block:(ctx: Context, params: Map) -> Map?) {
75 | channelList[name] = block
76 | }
77 | fun routeObj(name: String, block:(ctx: Context, params: Map) -> Map?) {
78 | channelList[name] = block
79 | }
80 | fun routeObjList(name: String, block:(ctx: Context, params: Map) -> List