Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c890dde7
Commit
c890dde7
authored
Aug 19, 2015
by
Collin Jackson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split fitness app’s UserData into UserData and UserDataImpl
parent
09216794
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
22 deletions
+23
-22
main.dart
examples/fitness/lib/main.dart
+17
-16
settings.dart
examples/fitness/lib/settings.dart
+4
-4
user_data.dart
examples/fitness/lib/user_data.dart
+2
-2
No files found.
examples/fitness/lib/main.dart
View file @
c890dde7
...
...
@@ -20,15 +20,20 @@ part 'meal.dart';
part
'measurement.dart'
;
part
'settings.dart'
;
class
UserData
{
UserData
();
abstract
class
UserData
{
BackupMode
get
backupMode
;
List
<
FitnessItem
>
get
items
;
}
class
UserDataImpl
extends
UserData
{
UserDataImpl
();
List
<
FitnessItem
>
_items
=
[];
BackupMode
_backup
Setting
;
BackupMode
get
backup
Setting
=>
_backupSetting
;
BackupMode
_backup
Mode
;
BackupMode
get
backup
Mode
=>
_backupMode
;
void
setBackupModeAndSave
(
BackupMode
value
)
{
_backup
Setting
=
value
;
_backup
Mode
=
value
;
save
();
}
...
...
@@ -56,12 +61,12 @@ class UserData {
Future
save
()
=>
saveFitnessData
(
this
);
UserData
.
fromJson
(
Map
json
)
{
UserData
Impl
.
fromJson
(
Map
json
)
{
json
[
'items'
].
forEach
((
item
)
{
_items
.
add
(
new
Measurement
.
fromJson
(
item
));
});
try
{
_backup
Setting
=
BackupMode
.
values
.
firstWhere
((
BackupMode
mode
)
{
_backup
Mode
=
BackupMode
.
values
.
firstWhere
((
BackupMode
mode
)
{
return
mode
.
toString
()
==
json
[
'backupMode'
];
});
}
catch
(
e
)
{
...
...
@@ -72,14 +77,14 @@ class UserData {
Map
toJson
()
{
Map
json
=
new
Map
();
json
[
'items'
]
=
_items
.
map
((
item
)
=>
item
.
toJson
()).
toList
();
json
[
'backupMode'
]
=
_backup
Setting
.
toString
();
json
[
'backupMode'
]
=
_backup
Mode
.
toString
();
return
json
;
}
}
class
FitnessApp
extends
App
{
NavigationState
_navigationState
;
UserData
_userData
=
new
UserData
();
UserData
Impl
_userData
=
new
UserDataImpl
();
void
didMount
()
{
super
.
didMount
();
...
...
@@ -88,10 +93,6 @@ class FitnessApp extends App {
}).
catchError
((
e
)
=>
print
(
"Failed to load data:
$e
"
));
}
void
save
()
{
_userData
.
save
().
catchError
((
e
)
=>
print
(
"Failed to load data:
$e
"
));
}
void
initState
()
{
_navigationState
=
new
NavigationState
([
new
Route
(
...
...
@@ -120,9 +121,9 @@ class FitnessApp extends App {
new
Route
(
name:
'/settings'
,
builder:
(
navigator
,
route
)
=>
new
SettingsFragment
(
navigator
,
_userData
.
backupSetting
,
settingsUpdater
navigator
:
navigator
,
userData:
_userData
as
UserData
,
updater:
settingsUpdater
)
),
]);
...
...
examples/fitness/lib/settings.dart
View file @
c890dde7
...
...
@@ -10,10 +10,10 @@ typedef void SettingsUpdater({
class
SettingsFragment
extends
Component
{
SettingsFragment
(
this
.
navigator
,
this
.
backup
,
this
.
updater
);
SettingsFragment
(
{
this
.
navigator
,
this
.
userData
,
this
.
updater
}
);
final
Navigator
navigator
;
final
BackupMode
backup
;
final
UserData
userData
;
final
SettingsUpdater
updater
;
void
_handleBackupChanged
(
bool
value
)
{
...
...
@@ -38,10 +38,10 @@ class SettingsFragment extends Component {
padding:
const
EdgeDims
.
symmetric
(
vertical:
20.0
),
child:
new
Block
([
new
DrawerItem
(
onPressed:
()
{
_handleBackupChanged
(!(
backup
==
BackupMode
.
enabled
));
},
onPressed:
()
{
_handleBackupChanged
(!(
userData
.
backupMode
==
BackupMode
.
enabled
));
},
children:
[
new
Flexible
(
child:
new
Text
(
'Back up data to the cloud'
)),
new
Switch
(
value:
backup
==
BackupMode
.
enabled
,
onChanged:
_handleBackupChanged
)
new
Switch
(
value:
userData
.
backupMode
==
BackupMode
.
enabled
,
onChanged:
_handleBackupChanged
)
]
)
])
...
...
examples/fitness/lib/user_data.dart
View file @
c890dde7
...
...
@@ -26,11 +26,11 @@ Future<UserData> loadFitnessData() async {
print
(
"Loading from
$dataPath
"
);
JsonDecoder
decoder
=
new
JsonDecoder
();
Map
data
=
await
decoder
.
convert
(
await
new
File
(
dataPath
).
readAsString
());
return
new
UserData
.
fromJson
(
data
);
return
new
UserData
Impl
.
fromJson
(
data
);
}
// Intentionally synchronous for execution just before shutdown.
Future
saveFitnessData
(
UserData
data
)
async
{
Future
saveFitnessData
(
UserData
Impl
data
)
async
{
String
dataPath
=
await
dataFilePath
();
print
(
"Saving to
$dataPath
"
);
JsonEncoder
encoder
=
new
JsonEncoder
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment