Android: Follow systemTheme on longTap on themeSwitchWidget

This commit is contained in:
Neeraj Gupta 2022-07-13 10:33:05 +05:30
parent 3b9d4d3643
commit 8e7f1cf28f
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1

View file

@ -2,6 +2,7 @@ import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:animated_toggle_switch/animated_toggle_switch.dart';
import 'package:flutter/material.dart';
import 'package:photos/ente_theme_data.dart';
import 'package:photos/utils/toast_util.dart';
class ThemeSwitchWidget extends StatelessWidget {
const ThemeSwitchWidget({Key key}) : super(key: key);
@ -12,41 +13,47 @@ class ThemeSwitchWidget extends StatelessWidget {
if (Theme.of(context).brightness == Brightness.dark) {
selectedTheme = 1;
}
return AnimatedToggleSwitch<int>.rolling(
current: selectedTheme,
values: const [0, 1],
onChanged: (i) {
debugPrint("Changed to {i}, selectedTheme is {selectedTheme} ");
if (i == 0) {
AdaptiveTheme.of(context).setLight();
} else {
AdaptiveTheme.of(context).setDark();
}
return GestureDetector(
onLongPress: () {
AdaptiveTheme.of(context).setSystem();
showShortToast(context, 'Following system theme');
},
iconBuilder: (i, size, foreground) {
final color = selectedTheme == i
? Theme.of(context).colorScheme.themeSwitchActiveIconColor
: Theme.of(context).colorScheme.themeSwitchInactiveIconColor;
if (i == 0) {
return Icon(
Icons.light_mode,
color: color,
);
} else {
return Icon(
Icons.dark_mode,
color: color,
);
}
},
height: 36,
indicatorSize: const Size(36, 36),
indicatorColor: Theme.of(context).colorScheme.themeSwitchIndicatorColor,
borderColor: Theme.of(context)
.colorScheme
.themeSwitchInactiveIconColor
.withOpacity(0.1),
borderWidth: 1,
child: AnimatedToggleSwitch<int>.rolling(
current: selectedTheme,
values: const [0, 1],
onChanged: (i) {
debugPrint("Changed to {i}, selectedTheme is {selectedTheme} ");
if (i == 0) {
AdaptiveTheme.of(context).setLight();
} else {
AdaptiveTheme.of(context).setDark();
}
},
iconBuilder: (i, size, foreground) {
final color = selectedTheme == i
? Theme.of(context).colorScheme.themeSwitchActiveIconColor
: Theme.of(context).colorScheme.themeSwitchInactiveIconColor;
if (i == 0) {
return Icon(
Icons.light_mode,
color: color,
);
} else {
return Icon(
Icons.dark_mode,
color: color,
);
}
},
height: 36,
indicatorSize: const Size(36, 36),
indicatorColor: Theme.of(context).colorScheme.themeSwitchIndicatorColor,
borderColor: Theme.of(context)
.colorScheme
.themeSwitchInactiveIconColor
.withOpacity(0.1),
borderWidth: 1,
),
);
}
}