Skip to content

Commit

Permalink
Adapt to device theme
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekmedia committed Nov 12, 2021
1 parent 064a602 commit 6e5d84d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 31 deletions.
23 changes: 10 additions & 13 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ class MyApp extends ConsumerWidget {

@override
Widget build(context, ref) {
return GnomeTheme(
isDark: ref.watch(forceDarkThemeProvider),
builder: (context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: GnomeTheme.of(context).themeData,
home: const HomePage(),
);
});
return MaterialApp(
debugShowCheckedModeBanner: false,
darkTheme: adwaitaDark,
theme: adwaitaLight,
themeMode: ref.watch(forceDarkThemeProvider),
home: const HomePage(),
);
}
}

class HomePage extends StatefulHookWidget {
// bool _isConnected = true;

const HomePage({Key? key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}
Expand Down Expand Up @@ -163,7 +160,7 @@ class _HomePageState extends State<HomePage> {
center: toggleSearch.value
? Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
color: GnomeTheme.of(context).sidebars,
color: Theme.of(context).sidebars,
constraints: BoxConstraints.loose(const Size(500, 50)),
child: RawKeyboardListener(
child: TextField(
Expand Down Expand Up @@ -380,7 +377,7 @@ class _HomePageState extends State<HomePage> {
Container(
height: 35,
padding: const EdgeInsets.symmetric(horizontal: 10),
decoration: BoxDecoration(color: GnomeTheme.of(context).sidebars, borderRadius: BorderRadius.circular(10)),
decoration: BoxDecoration(color: Theme.of(context).sidebars, borderRadius: BorderRadius.circular(10)),
child: DropdownButton<int>(
value: index,
onChanged: onChanged,
Expand Down
13 changes: 7 additions & 6 deletions lib/providers/force_dark_theme.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:appimagepool/utils/utils.dart';

final forceDarkThemeProvider = StateNotifierProvider<ForceDarkThemeNotifier, bool>((ref) {
final forceDarkThemeProvider = StateNotifierProvider<ForceDarkThemeNotifier, ThemeMode>((ref) {
return ForceDarkThemeNotifier(
MyPrefs().prefs.getBool('forceDarkTheme') ?? false,
ThemeMode.values.firstWhere((ele) => ele.index == (MyPrefs().prefs.getInt('forceDark') ?? 2)),
);
});

class ForceDarkThemeNotifier extends StateNotifier<bool> {
class ForceDarkThemeNotifier extends StateNotifier<ThemeMode> {
ForceDarkThemeNotifier(state) : super(state);

toggle() {
state = !state;
MyPrefs().prefs.setBool('forceDarkTheme', state);
toggle(Brightness brightness) {
state = brightness == Brightness.dark ? ThemeMode.light : ThemeMode.dark;
MyPrefs().prefs.setInt('forceDark', state.index);
}
}
2 changes: 1 addition & 1 deletion lib/screens/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AppPage extends HookConsumerWidget {
body: ListView(
children: [
Container(
color: GnomeTheme.of(context).sidebars,
color: Theme.of(context).sidebars,
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 40, vertical: 10),
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/custom_license_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class LicenseInfoPage extends ConsumerWidget {
var currentPara = cParagraph![index].paragraphs.toList();
return StickyHeader(
header: Container(
color: GnomeTheme.of(context).sidebars,
color: Theme.of(context).sidebars,
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 15),
alignment: Alignment.centerLeft,
child: Text(currentPara[0].text),
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ extension Context on BuildContext {
TextTheme get textTheme => Theme.of(this).textTheme;
ThemeData get theme => Theme.of(this);

bool get isDark => Theme.of(this).brightness == Brightness.dark;
Brightness get brightness => Theme.of(this).brightness;
bool get isDark => brightness == Brightness.dark;
back() => Navigator.of(this).pop();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/carousel_arrow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CarouselArrow extends ConsumerWidget {
height: 44,
decoration: ShapeDecoration(
shape: const CircleBorder(),
color: GnomeTheme.of(context).sidebars.withOpacity(0.70),
color: Theme.of(context).sidebars.withOpacity(0.70),
),
child: Center(child: Icon(icon, color: context.textTheme.bodyText1!.color, size: 30)),
),
Expand Down
10 changes: 4 additions & 6 deletions lib/widgets/prefs_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class PrefsWidget extends HookConsumerWidget {
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: context.theme.canvasColor,
color: Theme.of(context).bgColor,
border: Border.all(color: Colors.grey),
),
child: DropdownButton<ThemeType>(
Expand Down Expand Up @@ -118,9 +118,7 @@ class PrefsWidget extends HookConsumerWidget {
),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: GnomeTheme.of(context).sidebars,
),
style: ElevatedButton.styleFrom(primary: Theme.of(context).sidebars),
onPressed: !isBrowserActive.value
? () async {
isBrowserActive.value = true;
Expand All @@ -143,10 +141,10 @@ class PrefsWidget extends HookConsumerWidget {
children: [
const Text('Force dark theme'),
CupertinoSwitch(
value: ref.watch(forceDarkThemeProvider),
value: context.isDark,
activeColor: context.theme.primaryColor,
onChanged: (value) {
ref.read(forceDarkThemeProvider.notifier).toggle();
ref.read(forceDarkThemeProvider.notifier).toggle(context.brightness);
},
),
],
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ packages:
name: gtk
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0-rc.5"
version: "1.0.0-rc.9"
hooks_riverpod:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
file_picker: ^4.1.2
flutter_spinkit: ^5.1.0
flutter_svg: ^0.23.0+1
gtk: ^1.0.0-rc.5
gtk: ^1.0.0-rc.9
hooks_riverpod: ^1.0.0-dev.7
intl: ^0.17.0
lucide_icons: ^0.16.13
Expand Down

0 comments on commit 6e5d84d

Please sign in to comment.