1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* @author lsy
* @date 2019-09-25
**/
import 'package:flutter/services.dart';
const String SAVE_STRING_SHARED = "SAVE_STRING_SHARED";
const String SAVE_INT_SHARED = "SAVE_INT_SHARED";
const String SAVE_FLOAT_SHARED = "SAVE_FLOAT_SHARED";
const String SAVE_BOOLEAN_SHARED = "SAVE_BOOLEAN_SHARED";
const String SAVE_STRINGLIST_SHARED = "SAVE_STRINGLIST_SHARED";
const String GET_STRING_SHARED = "GET_STRING_SHARED";
const String GET_INT_SHARED = "GET_INT_SHARED";
const String GET_FLOAT_SHARED = "GET_FLOAT_SHARED";
const String GET_BOOLEAN_SHARED = "GET_BOOLEAN_SHARED";
const String GET_STRINGLIST_SHARED = "GET_STRINGLIST_SHARED";
class SharedPlugin {
static Future<bool> saveString(
String key, String value, MethodChannel channel) async {
return await channel
.invokeMethod(SAVE_STRING_SHARED, {"key": key, "value": value});
}
static Future<bool> saveInt(
String key, int value, MethodChannel channel) async {
return await channel
.invokeMethod(SAVE_INT_SHARED, {"key": key, "value": value});
}
static Future<bool> saveDouble(
String key, double value, MethodChannel channel) async {
return await channel
.invokeMethod(SAVE_FLOAT_SHARED, {"key": key, "value": value});
}
static Future<bool> saveBoolean(
String key, bool value, MethodChannel channel) async {
return await channel
.invokeMethod(SAVE_BOOLEAN_SHARED, {"key": key, "value": value});
}
static Future<bool> saveStringList(
String key, List<String> value, MethodChannel channel) async {
return await channel
.invokeMethod(SAVE_STRINGLIST_SHARED, {"key": key, "value": value});
}
static Future<String> getString(
String key, String value, MethodChannel channel) async {
return await channel
.invokeMethod(GET_STRING_SHARED, {"key": key, "value": value});
}
static Future<int> getInt(
String key, int value, MethodChannel channel) async {
return await channel
.invokeMethod(GET_INT_SHARED, {"key": key, "value": value});
}
static Future<double> getDouble(
String key, double value, MethodChannel channel) async {
return await channel
.invokeMethod(GET_FLOAT_SHARED, {"key": key, "value": value});
}
static Future<bool> getBoolean(
String key, bool value, MethodChannel channel) async {
return await channel
.invokeMethod(GET_BOOLEAN_SHARED, {"key": key, "value": value});
}
static Future<List<String>> getStringList(
String key, List<String> value, MethodChannel channel) async {
List list = await channel
.invokeMethod(GET_STRINGLIST_SHARED, {"key": key, "value": value});
if(list==null){
print("LIST IS NULLL!!!! ");
return Future.value(null);
}
List<String> finalList = [];
list.forEach((value) {
String temp = value as String;
finalList.add(temp);
});
return Future.value(finalList);
}
}