Add a dark mode switcher in the App Drawer

Inspired by Telegram, though our animation is not as fancy.

Related to #121
This commit is contained in:
Vishesh Handa
2020-09-04 02:21:22 +02:00
parent a05e9d04de
commit 96bbef436b

View File

@ -2,6 +2,7 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_email_sender/flutter_email_sender.dart'; import 'package:flutter_email_sender/flutter_email_sender.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
@ -299,6 +300,16 @@ class _AppDrawerHeader extends StatelessWidget {
child: ProButton(), 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, 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);
},
);
}
}