From b754c796393f607e0f94cab53ef4d536201d4614 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 30 Nov 2020 21:53:58 +0100 Subject: [PATCH] Move AppDrawerHeader to its own file --- lib/widgets/app_drawer.dart | 111 +--------------------------- lib/widgets/app_drawer_header.dart | 114 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 109 deletions(-) create mode 100644 lib/widgets/app_drawer_header.dart diff --git a/lib/widgets/app_drawer.dart b/lib/widgets/app_drawer.dart index 2c51d3d1..72d6352d 100644 --- a/lib/widgets/app_drawer.dart +++ b/lib/widgets/app_drawer.dart @@ -2,10 +2,10 @@ 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'; +import 'package:gitjournal/widgets/app_drawer_header.dart'; import 'package:launch_review/launch_review.dart'; import 'package:provider/provider.dart'; import 'package:share/share.dart'; @@ -50,7 +50,7 @@ class AppDrawer extends StatelessWidget { // Important: Remove any padding from the ListView. padding: EdgeInsets.zero, children: [ - _AppDrawerHeader(), + AppDrawerHeader(), if (setupGitButton != null) ...[setupGitButton, divider], if (!appSettings.proMode) _buildDrawerTile( @@ -284,110 +284,3 @@ void _navTopLevel(BuildContext context, String toRoute) { Navigator.pushNamed(context, toRoute); } } - -class _AppDrawerHeader extends StatelessWidget { - @override - Widget build(BuildContext context) { - var appSettings = Provider.of(context); - - return Stack( - children: [ - DrawerHeader( - margin: const EdgeInsets.all(0.0), - decoration: BoxDecoration( - color: Theme.of(context).highlightColor, - ), - child: const Padding( - padding: EdgeInsets.all(8.0), - child: DecoratedBox( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/icon/icon.png'), - ), - ), - ), - ), - ), - /* - Positioned.fill( - child: Align( - alignment: Alignment.centerLeft, - child: IconButton( - padding: const EdgeInsets.all(0), - icon: Icon(Icons.arrow_left, size: 42.0), - onPressed: () {}, - ), - ), - ), - Positioned.fill( - child: Align( - alignment: Alignment.centerRight, - child: IconButton( - padding: const EdgeInsets.all(0), - icon: Icon(Icons.arrow_right, size: 42.0), - onPressed: () {}, - ), - ), - ), - */ - if (appSettings.proMode) - Positioned.fill( - child: Align( - alignment: Alignment.bottomRight, - 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, - ); - } -} - -class ProButton extends StatelessWidget { - @override - Widget build(BuildContext context) { - var theme = Theme.of(context); - - return Padding( - padding: const EdgeInsets.all(16.0), - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(10), - color: theme.scaffoldBackgroundColor, - boxShadow: [ - BoxShadow(color: theme.accentColor, spreadRadius: 0), - ], - ), - padding: const EdgeInsets.all(8.0), - child: Text('PRO', style: theme.textTheme.button), - ), - ); - } -} - -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); - }, - ); - } -} diff --git a/lib/widgets/app_drawer_header.dart b/lib/widgets/app_drawer_header.dart new file mode 100644 index 00000000..43a10017 --- /dev/null +++ b/lib/widgets/app_drawer_header.dart @@ -0,0 +1,114 @@ +import 'package:flutter/material.dart'; + +import 'package:dynamic_theme/dynamic_theme.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:provider/provider.dart'; + +import 'package:gitjournal/app_settings.dart'; + +class AppDrawerHeader extends StatelessWidget { + @override + Widget build(BuildContext context) { + var appSettings = Provider.of(context); + + return Stack( + children: [ + DrawerHeader( + margin: const EdgeInsets.all(0.0), + decoration: BoxDecoration( + color: Theme.of(context).highlightColor, + ), + child: const Padding( + padding: EdgeInsets.all(8.0), + child: DecoratedBox( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/icon/icon.png'), + ), + ), + ), + ), + ), + /* + Positioned.fill( + child: Align( + alignment: Alignment.centerLeft, + child: IconButton( + padding: const EdgeInsets.all(0), + icon: Icon(Icons.arrow_left, size: 42.0), + onPressed: () {}, + ), + ), + ), + Positioned.fill( + child: Align( + alignment: Alignment.centerRight, + child: IconButton( + padding: const EdgeInsets.all(0), + icon: Icon(Icons.arrow_right, size: 42.0), + onPressed: () {}, + ), + ), + ), + */ + if (appSettings.proMode) + Positioned.fill( + child: Align( + alignment: Alignment.bottomRight, + 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, + ); + } +} + +class ProButton extends StatelessWidget { + @override + Widget build(BuildContext context) { + var theme = Theme.of(context); + + return Padding( + padding: const EdgeInsets.all(16.0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10), + color: theme.scaffoldBackgroundColor, + boxShadow: [ + BoxShadow(color: theme.accentColor, spreadRadius: 0), + ], + ), + padding: const EdgeInsets.all(8.0), + child: Text('PRO', style: theme.textTheme.button), + ), + ); + } +} + +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); + }, + ); + } +}