Skip to content

Commit ea968f7

Browse files
thamaraiselvamthamaraiselvam
authored andcommitted
SharedPreferences fetch and set is done
1 parent 9a22b47 commit ea968f7

File tree

17 files changed

+318
-64
lines changed

17 files changed

+318
-64
lines changed

ios/Flutter/Debug.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
12
#include "Generated.xcconfig"

ios/Flutter/Release.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
12
#include "Generated.xcconfig"

ios/Podfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Uncomment this line to define a global platform for your project
2+
# platform :ios, '9.0'
3+
4+
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5+
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6+
7+
project 'Runner', {
8+
'Debug' => :debug,
9+
'Profile' => :release,
10+
'Release' => :release,
11+
}
12+
13+
def parse_KV_file(file, separator='=')
14+
file_abs_path = File.expand_path(file)
15+
if !File.exists? file_abs_path
16+
return [];
17+
end
18+
pods_ary = []
19+
skip_line_start_symbols = ["#", "/"]
20+
File.foreach(file_abs_path) { |line|
21+
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
22+
plugin = line.split(pattern=separator)
23+
if plugin.length == 2
24+
podname = plugin[0].strip()
25+
path = plugin[1].strip()
26+
podpath = File.expand_path("#{path}", file_abs_path)
27+
pods_ary.push({:name => podname, :path => podpath});
28+
else
29+
puts "Invalid plugin specification: #{line}"
30+
end
31+
}
32+
return pods_ary
33+
end
34+
35+
target 'Runner' do
36+
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
37+
# referring to absolute paths on developers' machines.
38+
system('rm -rf .symlinks')
39+
system('mkdir -p .symlinks/plugins')
40+
41+
# Flutter Pods
42+
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
43+
if generated_xcode_build_settings.empty?
44+
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
45+
end
46+
generated_xcode_build_settings.map { |p|
47+
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
48+
symlink = File.join('.symlinks', 'flutter')
49+
File.symlink(File.dirname(p[:path]), symlink)
50+
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
51+
end
52+
}
53+
54+
# Plugin Pods
55+
plugin_pods = parse_KV_file('../.flutter-plugins')
56+
plugin_pods.map { |p|
57+
symlink = File.join('.symlinks', 'plugins', p[:name])
58+
File.symlink(p[:path], symlink)
59+
pod p[:name], :path => File.join(symlink, 'ios')
60+
}
61+
end
62+
63+
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
64+
install! 'cocoapods', :disable_input_output_paths => true
65+
66+
post_install do |installer|
67+
installer.pods_project.targets.each do |target|
68+
target.build_configurations.each do |config|
69+
config.build_settings['ENABLE_BITCODE'] = 'NO'
70+
end
71+
end
72+
end

ios/Podfile.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PODS:
2+
- Flutter (1.0.0)
3+
- shared_preferences (0.0.1):
4+
- Flutter
5+
6+
DEPENDENCIES:
7+
- Flutter (from `.symlinks/flutter/ios`)
8+
- shared_preferences (from `.symlinks/plugins/shared_preferences/ios`)
9+
10+
EXTERNAL SOURCES:
11+
Flutter:
12+
:path: ".symlinks/flutter/ios"
13+
shared_preferences:
14+
:path: ".symlinks/plugins/shared_preferences/ios"
15+
16+
SPEC CHECKSUMS:
17+
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
18+
shared_preferences: 1feebfa37bb57264736e16865e7ffae7fc99b523
19+
20+
PODFILE CHECKSUM: 7fb83752f59ead6285236625b82473f90b1cb932
21+
22+
COCOAPODS: 1.7.4

ios/Runner.xcodeproj/project.pbxproj

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1212
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
1313
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
14+
652C2B53023150BB0EDDC59C /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8AFBEDA2E2EAA99BEE83EEA8 /* libPods-Runner.a */; };
1415
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
1516
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1617
9740EEB41CF90195004384FC /* Debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 9740EEB21CF90195004384FC /* Debug.xcconfig */; };
@@ -39,11 +40,15 @@
3940
/* Begin PBXFileReference section */
4041
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4142
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
43+
34FA875C6803D1D6F88941C4 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
4244
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
4345
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
46+
48B9C4E907B764B2B42F000B /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
47+
4BF8EE24F0C79A3F3A630809 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
4448
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4549
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
4650
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
51+
8AFBEDA2E2EAA99BEE83EEA8 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4752
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
4853
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
4954
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
@@ -62,12 +67,21 @@
6267
files = (
6368
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
6469
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
70+
652C2B53023150BB0EDDC59C /* libPods-Runner.a in Frameworks */,
6571
);
6672
runOnlyForDeploymentPostprocessing = 0;
6773
};
6874
/* End PBXFrameworksBuildPhase section */
6975

7076
/* Begin PBXGroup section */
77+
2952341FF069532874BE98D7 /* Frameworks */ = {
78+
isa = PBXGroup;
79+
children = (
80+
8AFBEDA2E2EAA99BEE83EEA8 /* libPods-Runner.a */,
81+
);
82+
name = Frameworks;
83+
sourceTree = "<group>";
84+
};
7185
9740EEB11CF90186004384FC /* Flutter */ = {
7286
isa = PBXGroup;
7387
children = (
@@ -87,7 +101,8 @@
87101
9740EEB11CF90186004384FC /* Flutter */,
88102
97C146F01CF9000F007C117D /* Runner */,
89103
97C146EF1CF9000F007C117D /* Products */,
90-
CF3B75C9A7D2FA2A4C99F110 /* Frameworks */,
104+
CB21145835C738CABB3C9327 /* Pods */,
105+
2952341FF069532874BE98D7 /* Frameworks */,
91106
);
92107
sourceTree = "<group>";
93108
};
@@ -123,19 +138,32 @@
123138
name = "Supporting Files";
124139
sourceTree = "<group>";
125140
};
141+
CB21145835C738CABB3C9327 /* Pods */ = {
142+
isa = PBXGroup;
143+
children = (
144+
48B9C4E907B764B2B42F000B /* Pods-Runner.debug.xcconfig */,
145+
4BF8EE24F0C79A3F3A630809 /* Pods-Runner.release.xcconfig */,
146+
34FA875C6803D1D6F88941C4 /* Pods-Runner.profile.xcconfig */,
147+
);
148+
name = Pods;
149+
path = Pods;
150+
sourceTree = "<group>";
151+
};
126152
/* End PBXGroup section */
127153

128154
/* Begin PBXNativeTarget section */
129155
97C146ED1CF9000F007C117D /* Runner */ = {
130156
isa = PBXNativeTarget;
131157
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
132158
buildPhases = (
159+
569B7FAED77F54A00E515C79 /* [CP] Check Pods Manifest.lock */,
133160
9740EEB61CF901F6004384FC /* Run Script */,
134161
97C146EA1CF9000F007C117D /* Sources */,
135162
97C146EB1CF9000F007C117D /* Frameworks */,
136163
97C146EC1CF9000F007C117D /* Resources */,
137164
9705A1C41CF9048500538489 /* Embed Frameworks */,
138165
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
166+
FB7983D854EF43AAEAF25903 /* [CP] Embed Pods Frameworks */,
139167
);
140168
buildRules = (
141169
);
@@ -208,6 +236,28 @@
208236
shellPath = /bin/sh;
209237
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
210238
};
239+
569B7FAED77F54A00E515C79 /* [CP] Check Pods Manifest.lock */ = {
240+
isa = PBXShellScriptBuildPhase;
241+
buildActionMask = 2147483647;
242+
files = (
243+
);
244+
inputFileListPaths = (
245+
);
246+
inputPaths = (
247+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
248+
"${PODS_ROOT}/Manifest.lock",
249+
);
250+
name = "[CP] Check Pods Manifest.lock";
251+
outputFileListPaths = (
252+
);
253+
outputPaths = (
254+
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
255+
);
256+
runOnlyForDeploymentPostprocessing = 0;
257+
shellPath = /bin/sh;
258+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
259+
showEnvVarsInLog = 0;
260+
};
211261
9740EEB61CF901F6004384FC /* Run Script */ = {
212262
isa = PBXShellScriptBuildPhase;
213263
buildActionMask = 2147483647;
@@ -222,6 +272,21 @@
222272
shellPath = /bin/sh;
223273
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
224274
};
275+
FB7983D854EF43AAEAF25903 /* [CP] Embed Pods Frameworks */ = {
276+
isa = PBXShellScriptBuildPhase;
277+
buildActionMask = 2147483647;
278+
files = (
279+
);
280+
inputPaths = (
281+
);
282+
name = "[CP] Embed Pods Frameworks";
283+
outputPaths = (
284+
);
285+
runOnlyForDeploymentPostprocessing = 0;
286+
shellPath = /bin/sh;
287+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
288+
showEnvVarsInLog = 0;
289+
};
225290
/* End PBXShellScriptBuildPhase section */
226291

227292
/* Begin PBXSourcesBuildPhase section */

ios/Runner.xcworkspace/contents.xcworkspacedata

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/component/ScoreCard.dart

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import 'package:flutter/material.dart';
2+
import 'package:numbers/provider/ScoreStore.dart';
23
import 'package:numbers/utils/constants.dart';
34
import 'package:numbers/widgets/dashedLine.dart';
4-
import 'package:numbers/widgets/tableRow.dart';
5+
import 'package:numbers/widgets/recentScore.dart';
56

6-
class ScoreBoard extends StatelessWidget {
7-
String title;
7+
class ScoreBoard extends StatefulWidget {
8+
final String title;
89
ScoreBoard(this.title);
910

11+
@override
12+
_ScoreBoardState createState() => _ScoreBoardState();
13+
}
14+
15+
class _ScoreBoardState extends State<ScoreBoard> {
16+
List recentScore = [];
17+
Map scoreCardMeta = {};
18+
@override
19+
void initState() {
20+
super.initState();
21+
_getRecentScore();
22+
}
23+
24+
void _getRecentScore() {
25+
ScoreStore().getRecentScore().then((score) {
26+
setState(() {
27+
this.recentScore = score;
28+
});
29+
});
30+
}
31+
1032
@override
1133
Widget build(BuildContext context) {
1234
return Container(
@@ -22,42 +44,20 @@ class ScoreBoard extends StatelessWidget {
2244
Icons.show_chart,
2345
color: primaryColor,
2446
),
25-
title: Text(title,
47+
title: Text(widget.title,
2648
style: TextStyle(
2749
color: primaryColor, fontWeight: FontWeight.bold)),
2850
),
2951
dashedLineBreak(Colors.grey),
30-
Table(
31-
columnWidths: {
32-
0: FractionColumnWidth(0.2),
33-
1: FractionColumnWidth(0.7),
34-
2: FractionColumnWidth(0.2)
35-
},
36-
children: [
37-
buildTableRow("Rank,Name,Score"),
38-
],
39-
),
40-
ListView.builder(
41-
itemCount: 5,
42-
shrinkWrap: true,
43-
// physics: const NeverScrollableScrollPhysics(),
44-
itemExtent: 35,
45-
itemBuilder: (BuildContext context, int index) {
46-
return ListTile(
47-
leading: Text(
48-
index.toString(),
49-
style: TextStyle(color: greyFontColor, fontSize: 13),
50-
),
51-
title: Text(
52-
'Thamaraiselvam',
53-
style: TextStyle(color: greyFontColor, fontSize: 13),
54-
),
55-
trailing: Text(index.toString() + ' days ago',
56-
style: TextStyle(color: greyFontColor, fontSize: 13)),
57-
);
58-
},
59-
),
60-
SizedBox(height: 15,)
52+
(this.recentScore.length == 0)
53+
? Padding(
54+
padding: const EdgeInsets.only(top: 20),
55+
child: Text('No data found, Play some games'),
56+
)
57+
: buildTableRow(this.recentScore),
58+
SizedBox(
59+
height: 15,
60+
)
6161
],
6262
),
6363
),

lib/provider/ScoreStore.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'dart:convert';
2+
import 'package:numbers/service/RecentScoreService.dart';
3+
import 'package:shared_preferences/shared_preferences.dart';
4+
5+
class ScoreStore {
6+
SharedPreferences prefs;
7+
8+
final String scoreKey = 'recentScoreDummy';
9+
final maxStoreLength = 3;
10+
11+
init() async {
12+
if (this.prefs == null) {
13+
this.prefs = await SharedPreferences.getInstance();
14+
}
15+
}
16+
17+
updateRecentScore(int score) async {
18+
19+
await this.init();
20+
21+
List recentScores = await this.getRecentScore();
22+
23+
RecentScore newScore = RecentScore.manualPush(score.toString(), DateTime.now().millisecondsSinceEpoch.toString());
24+
25+
recentScores.insert(0, newScore);
26+
27+
if (recentScores.length > this.maxStoreLength) {
28+
recentScores.removeLast();
29+
}
30+
31+
return await this.prefs.setString(this.scoreKey, json.encode(recentScores));
32+
}
33+
34+
Future getRecentScore() async {
35+
await this.init();
36+
String recentScores = this.prefs.getString(this.scoreKey);
37+
return recentScores == null ? [] : recentScoreFromJson(recentScores);
38+
}
39+
}

0 commit comments

Comments
 (0)