From 96bbef436bf47c78f0f7aab35e12d06d3664c247 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Fri, 4 Sep 2020 02:21:22 +0200 Subject: [PATCH] Add a dark mode switcher in the App Drawer Inspired by Telegram, though our animation is not as fancy. Related to #121 --- lib/widgets/app_drawer.dart | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/widgets/app_drawer.dart b/lib/widgets/app_drawer.dart index 817efdb0..570c7841 100644 --- a/lib/widgets/app_drawer.dart +++ b/lib/widgets/app_drawer.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:dynamic_theme/dynamic_theme.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter_email_sender/flutter_email_sender.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -299,6 +300,16 @@ class _AppDrawerHeader extends StatelessWidget { child: ProButton(), ), ), + Positioned.fill( + child: Align( + alignment: Alignment.topRight, + child: SafeArea( + child: Padding( + padding: const EdgeInsets.fromLTRB(0, 16, 16, 0), + child: ThemeSwitcherButton(), + )), + ), + ), ], fit: StackFit.passthrough, ); @@ -326,3 +337,20 @@ class ProButton extends StatelessWidget { ); } } + +class ThemeSwitcherButton extends StatelessWidget { + @override + Widget build(BuildContext context) { + return GestureDetector( + child: const FaIcon(FontAwesomeIcons.solidMoon), + onTap: () { + var dynamicTheme = DynamicTheme.of(context); + var brightness = dynamicTheme.brightness; + + dynamicTheme.setBrightness(brightness == Brightness.light + ? Brightness.dark + : Brightness.light); + }, + ); + } +}