-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a33d01f
commit c6f05ad
Showing
15 changed files
with
614 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
extension BuildContextX on BuildContext { | ||
ThemeData get theme => Theme.of(this); | ||
bool get light => theme.brightness == Brightness.light; | ||
MediaQueryData get mq => MediaQuery.of(this); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const kAppName = 'pulse'; | ||
const kAppTitle = 'Pulse'; | ||
|
||
const kAppStateFileName = 'appstate.json'; | ||
const kSettingsFileName = 'settings.json'; | ||
const kFavLocationsFileName = 'favlocations.json'; | ||
const kLastLocation = 'lastLocation'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'dart:async'; | ||
|
||
import '../../constants.dart'; | ||
import '../../utils.dart'; | ||
|
||
class LocationsService { | ||
String? _lastLocation; | ||
String? get lastLocation => _lastLocation; | ||
void setLastLocation(String? value) { | ||
if (value == _lastLocation) return; | ||
writeAppState(kLastLocation, value).then((_) { | ||
_lastLocationController.add(true); | ||
_lastLocation = value; | ||
}); | ||
} | ||
|
||
final _lastLocationController = StreamController<bool>.broadcast(); | ||
Stream<bool> get lastLocationChanged => _lastLocationController.stream; | ||
|
||
Set<String> _favLocations = {}; | ||
Set<String> get favLocations => _favLocations; | ||
bool isFavLocation(String value) => _favLocations.contains(value); | ||
final _favLocationsController = StreamController<bool>.broadcast(); | ||
Stream<bool> get favLocationsChanged => _favLocationsController.stream; | ||
|
||
void addFavLocation(String name) { | ||
if (favLocations.contains(name)) return; | ||
_favLocations.add(name); | ||
writeStringIterable( | ||
iterable: _favLocations, | ||
filename: kFavLocationsFileName, | ||
).then((_) => _favLocationsController.add(true)); | ||
} | ||
|
||
Future<void> removeFavLocation(String name) async { | ||
if (!favLocations.contains(name)) return; | ||
_favLocations.remove(name); | ||
return writeStringIterable( | ||
iterable: _favLocations, | ||
filename: kFavLocationsFileName, | ||
).then((_) => _favLocationsController.add(true)); | ||
} | ||
|
||
Future<void> init() async { | ||
_lastLocation = (await readAppState(kLastLocation)) as String?; | ||
_favLocations = Set.from( | ||
(await readStringIterable(filename: kFavLocationsFileName) ?? <String>{}), | ||
); | ||
} | ||
|
||
Future<void> dispose() async { | ||
await _favLocationsController.close(); | ||
await _lastLocationController.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.