aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-06-03 14:39:52 +0530
committerAkshay Nair <phenax5@gmail.com>2020-06-03 14:39:52 +0530
commit871706b606c77eeac13bfcea67c3ce1d71203d2c (patch)
tree82d3ca8b51cc001606f5412a20730a813b7d9e2d
parentc745b90dfdc97a2e04582051b01fde83883d8e3e (diff)
downloaddaft-launcher-871706b606c77eeac13bfcea67c3ce1d71203d2c.tar.gz
daft-launcher-871706b606c77eeac13bfcea67c3ce1d71203d2c.zip
Adds shared preferences for config/theme storage + refactors a streamstate
Diffstat (limited to '')
-rw-r--r--.flutter-plugins-dependencies2
-rw-r--r--lib/components/SearchableAppList.dart6
-rw-r--r--lib/data/config.dart51
-rw-r--r--lib/helpers/StreamState.dart31
-rw-r--r--lib/main.dart52
-rw-r--r--lib/pages/Home.dart9
-rw-r--r--pubspec.lock7
-rw-r--r--pubspec.yaml1
8 files changed, 153 insertions, 6 deletions
diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies
index a4cc41f..3881cb6 100644
--- a/.flutter-plugins-dependencies
+++ b/.flutter-plugins-dependencies
@@ -1 +1 @@
-{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[],"android":[{"name":"android_intent","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.7+2/","dependencies":[]},{"name":"device_apps","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/device_apps-1.0.9/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"android_intent","dependencies":[]},{"name":"device_apps","dependencies":[]}],"date_created":"2020-06-03 00:33:49.915841","version":"1.19.0-2.0.pre.214"} \ No newline at end of file
+{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"shared_preferences","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.4.3/","dependencies":[]}],"android":[{"name":"android_intent","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/android_intent-0.3.7+2/","dependencies":[]},{"name":"device_apps","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/device_apps-1.0.9/","dependencies":[]},{"name":"shared_preferences","path":"/home/akshayn/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.4.3/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"android_intent","dependencies":[]},{"name":"device_apps","dependencies":[]},{"name":"shared_preferences","dependencies":[]}],"date_created":"2020-06-03 14:35:47.788356","version":"1.19.0-2.0.pre.214"} \ No newline at end of file
diff --git a/lib/components/SearchableAppList.dart b/lib/components/SearchableAppList.dart
index 8e0d818..f41ba18 100644
--- a/lib/components/SearchableAppList.dart
+++ b/lib/components/SearchableAppList.dart
@@ -21,6 +21,8 @@ class _SearchableAppListState extends State<SearchableAppList> {
@override
Widget build(BuildContext ctx) {
+ ThemeData theme = Theme.of(context);
+
return Column(
children: [
Container(
@@ -28,7 +30,9 @@ class _SearchableAppListState extends State<SearchableAppList> {
child: TextField(
onChanged: onInput,
decoration: InputDecoration(
- border: InputBorder.none,
+ prefixStyle: TextStyle(color: Color(0xFF888888)),
+ prefix: Text('/'),
+ hintStyle: TextStyle(color: Color(0xFFD8DEE9)),
hintText: 'Search',
),
),
diff --git a/lib/data/config.dart b/lib/data/config.dart
new file mode 100644
index 0000000..0dd33cd
--- /dev/null
+++ b/lib/data/config.dart
@@ -0,0 +1,51 @@
+import 'package:shared_preferences/shared_preferences.dart';
+import 'dart:async';
+
+String defaultTheme = 'dark';
+
+class Config {
+ String theme = defaultTheme;
+ Config({ this.theme }) {}
+
+ bool isDarkMode() {
+ return theme == 'dark';
+ }
+}
+
+StreamController<Config> config_$ = StreamController<Config>.broadcast();
+
+Future<Config> getConfig() async {
+ final prefs = await SharedPreferences.getInstance();
+
+ return Config(
+ theme: prefs.getString('theme'),
+ );
+}
+
+void initConfig() async {
+ Config c = await getConfig();
+ config_$.add(c);
+}
+
+Stream<Config> getConfig$() {
+ return config_$.stream;
+}
+
+void setConfig(Config config) async {
+ final prefs = await SharedPreferences.getInstance();
+
+ prefs.setString('theme', config.theme);
+
+ config_$.add(await getConfig());
+}
+
+void toggleTheme() async {
+ final config = await getConfig();
+
+ if (config.theme == 'dark') {
+ setConfig(Config(theme: 'light'));
+ } else {
+ setConfig(Config(theme: 'dark'));
+ }
+}
+
diff --git a/lib/helpers/StreamState.dart b/lib/helpers/StreamState.dart
new file mode 100644
index 0000000..3e329ed
--- /dev/null
+++ b/lib/helpers/StreamState.dart
@@ -0,0 +1,31 @@
+import 'dart:async';
+import 'package:flutter/material.dart';
+
+class StreamStateValue<Value> {
+ Stream<Value> stream$;
+ Value value;
+
+ StreamStateValue({ this.stream$, this.value }) {}
+
+ StreamSubscription initialize(void Function(void Function()) setState) {
+ return stream$.listen((Value v) {
+ setState(() { value = v; });
+ });
+ }
+}
+
+abstract class StreamState<T extends StatefulWidget> extends State<T> {
+ List<StreamSubscription> subs = <StreamSubscription>[];
+
+ void initStateValue<V>(StreamStateValue<V> streamVal) {
+ subs.add(streamVal.initialize(setState));
+ }
+
+ @override
+ void dispose() {
+ super.dispose();
+ for(StreamSubscription sub in subs) {
+ sub.cancel();
+ }
+ }
+}
diff --git a/lib/main.dart b/lib/main.dart
index 2ad0fb9..40aa069 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -4,23 +4,67 @@ import 'package:flutter/material.dart';
import 'pages/Home.dart';
import 'pages/Apps.dart';
+import 'data/config.dart';
+import 'helpers/StreamState.dart';
+
void main() {
runApp(MyApp());
}
-class MyApp extends StatelessWidget {
- final Stream<DateTime> time$ = Stream.periodic(Duration(seconds: 1), (_x) => DateTime.now()).asBroadcastStream();
+class MyAppState extends StreamState<MyApp> {
+ // Streams
+ StreamStateValue<Config> config = StreamStateValue<Config>(stream$: getConfig$(), value: Config());
+ final Stream<DateTime> time$ =
+ Stream.periodic(Duration(seconds: 1), (_x) => DateTime.now()).asBroadcastStream();
+
+ void initState() {
+ super.initState();
+ initStateValue(config);
+ }
@override
void dispose() {
+ super.dispose();
time$.drain();
}
+ ThemeData getLightTheme() {
+ return ThemeData(brightness: Brightness.light);
+ }
+
+ ThemeData getDarkTheme() {
+ Color fg = Color(0xFFD8DEE9);
+ return ThemeData(
+ backgroundColor: Color(0xFF0F1215),
+ scaffoldBackgroundColor: Color(0xFF0F1215),
+ accentColor: fg,
+ primaryColor: Color(0xFF5E81AC),
+ textTheme: TextTheme(
+ headline1: TextStyle(color: fg),
+ headline2: TextStyle(color: fg),
+ headline3: TextStyle(color: fg),
+ headline4: TextStyle(color: fg),
+ headline5: TextStyle(color: fg),
+ headline6: TextStyle(color: fg),
+ subtitle1: TextStyle(color: fg),
+ subtitle2: TextStyle(color: fg),
+ bodyText1: TextStyle(color: fg),
+ bodyText2: TextStyle(color: fg),
+ button: TextStyle(color: fg),
+ caption: TextStyle(color: fg),
+ overline: TextStyle(color: fg),
+ ),
+ );
+ }
+
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'owyn launcher',
+ theme: getLightTheme(),
+ darkTheme: getDarkTheme(),
+ themeMode: config.value.isDarkMode() ? ThemeMode.dark : ThemeMode.light,
home: Scaffold(
body: PageView(
controller: PageController(keepPage: true),
@@ -33,3 +77,7 @@ class MyApp extends StatelessWidget {
);
}
}
+
+class MyApp extends StatefulWidget {
+ MyAppState createState() => MyAppState();
+}
diff --git a/lib/pages/Home.dart b/lib/pages/Home.dart
index 1f4b473..8efa86e 100644
--- a/lib/pages/Home.dart
+++ b/lib/pages/Home.dart
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import '../components/FixedContainer.dart';
+import '../data/config.dart';
class StatusInfoCard extends StatelessWidget {
Stream<DateTime> time$;
@@ -10,7 +11,7 @@ class StatusInfoCard extends StatelessWidget {
StatusInfoCard(this.time$, { this.defaultTime }): super();
- final timeFormat = DateFormat('h:m a'); // H fr 24 hrs
+ final timeFormat = DateFormat('h:mm a'); // H fr 24 hrs
final dateFormat = DateFormat('EEEE, d MMM');
@override
@@ -42,12 +43,16 @@ class StatusInfoCard extends StatelessWidget {
fontWeight: FontWeight.w300,
),
),
+ FlatButton(
+ child: Text('Theme'),
+ onPressed: () { toggleTheme(); }
+ ),
]
);
}
return Container(
- height: 80,
+ height: 300,
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Align(alignment: Alignment.topLeft, child: child),
);
diff --git a/pubspec.lock b/pubspec.lock
index 17d71db..f73fff8 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -102,6 +102,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
+ shared_preferences:
+ dependency: "direct main"
+ description:
+ name: shared_preferences
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "0.4.3"
sky_engine:
dependency: transitive
description: flutter
diff --git a/pubspec.yaml b/pubspec.yaml
index 2228d29..f14d60b 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -26,6 +26,7 @@ dependencies:
intl: ^0.16.1
device_apps: ^1.0.9
android_intent: ^0.3.7
+ shared_preferences: ^0.4.3
dev_dependencies:
flutter_test: