AppDrawer: Show repo list

This is just a first attempt and all the values are hardcoded. This
needs lots more work.
This commit is contained in:
Vishesh Handa
2021-02-04 15:37:01 +01:00
parent e9c7adafd1
commit 2e9be69c7c
2 changed files with 104 additions and 57 deletions

View File

@ -17,7 +17,37 @@ import 'package:gitjournal/utils.dart';
import 'package:gitjournal/utils/logger.dart'; import 'package:gitjournal/utils/logger.dart';
import 'package:gitjournal/widgets/app_drawer_header.dart'; import 'package:gitjournal/widgets/app_drawer_header.dart';
class AppDrawer extends StatelessWidget { class AppDrawer extends StatefulWidget {
@override
_AppDrawerState createState() => _AppDrawerState();
}
class _AppDrawerState extends State<AppDrawer> {
bool repoChooserVisible = false;
List<Widget> _buildRepoList() {
var divider = Row(children: <Widget>[const Expanded(child: Divider())]);
return [
_buildDrawerTile(
context,
icon: FontAwesomeIcons.book,
isFontAwesome: true,
title: 'journal',
onTap: () => _navTopLevel(context, '/login'),
selected: false,
),
_buildDrawerTile(
context,
icon: Icons.add,
title: 'Add Repository',
onTap: () => _navTopLevel(context, '/login'),
selected: false,
),
divider,
];
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget setupGitButton; Widget setupGitButton;
@ -50,7 +80,16 @@ class AppDrawer extends StatelessWidget {
// Important: Remove any padding from the ListView. // Important: Remove any padding from the ListView.
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
children: <Widget>[ children: <Widget>[
AppDrawerHeader(), AppDrawerHeader(
showRepoList: repoChooserVisible,
repoListToggled: () {
setState(() {
repoChooserVisible = !repoChooserVisible;
});
},
),
// If they are multiple show the current one which a tick mark
if (repoChooserVisible) ..._buildRepoList(),
if (setupGitButton != null) ...[setupGitButton, divider], if (setupGitButton != null) ...[setupGitButton, divider],
if (!appSettings.proMode) if (!appSettings.proMode)
_buildDrawerTile( _buildDrawerTile(

View File

@ -1,85 +1,93 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:dynamic_theme/dynamic_theme.dart'; import 'package:dynamic_theme/dynamic_theme.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:function_types/function_types.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:gitjournal/app_settings.dart'; import 'package:gitjournal/app_settings.dart';
class AppDrawerHeader extends StatelessWidget { class AppDrawerHeader extends StatelessWidget {
final Func0<void> repoListToggled;
final bool showRepoList;
AppDrawerHeader({
@required this.repoListToggled,
@required this.showRepoList,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var appSettings = Provider.of<AppSettings>(context); var appSettings = Provider.of<AppSettings>(context);
var stack = Stack( var top = Row(
children: <Widget>[ children: <Widget>[
const Padding( const DecoratedBox(
padding: EdgeInsets.all(16.0), decoration: BoxDecoration(
child: DecoratedBox( image: DecorationImage(
decoration: BoxDecoration( image: AssetImage('assets/icon/icon.png'),
image: DecorationImage(
image: AssetImage('assets/icon/icon.png'),
),
), ),
), ),
child: SizedBox(width: 64, height: 64),
), ),
if (appSettings.proMode) Padding(
Positioned.fill( padding: const EdgeInsets.fromLTRB(0, 0, 8, 0),
child: Align( child: ThemeSwitcherButton(),
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ProButton(),
),
),
),
Positioned.fill(
child: Align(
alignment: Alignment.topRight,
child: SafeArea(
child: Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 8, 0),
child: ThemeSwitcherButton(),
),
),
),
), ),
], ],
fit: StackFit.passthrough, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
); );
/* var textTheme = Theme.of(context).textTheme;
var dropdownValue = 'One'; var repoSelector = Row(
var repoSelector = DropdownButton<String>( children: <Widget>[
value: dropdownValue, Column(
icon: const Icon(Icons.arrow_downward), children: <Widget>[
iconSize: 24, Text("journal", style: textTheme.headline6),
elevation: 16, const SizedBox(height: 8.0),
style: const TextStyle(color: Colors.deepPurple), Text("github.com/vhanda/journal", style: textTheme.subtitle2),
underline: Container( const SizedBox(height: 8.0),
height: 2, ],
color: Colors.deepPurpleAccent, crossAxisAlignment: CrossAxisAlignment.start,
), ),
onChanged: (String newValue) { IconButton(
dropdownValue = newValue; icon: FaIcon(showRepoList
}, ? FontAwesomeIcons.angleUp
items: <String>['One', 'Two', 'Free', 'Four'] : FontAwesomeIcons.angleDown),
.map<DropdownMenuItem<String>>((String value) { onPressed: repoListToggled,
return DropdownMenuItem<String>( ),
value: value, ],
child: Text(value), mainAxisAlignment: MainAxisAlignment.spaceBetween,
); crossAxisAlignment: CrossAxisAlignment.center,
}).toList(),
); );
*/
return DrawerHeader( var header = DrawerHeader(
margin: const EdgeInsets.all(0.0), margin: const EdgeInsets.all(0.0),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).highlightColor, color: Theme.of(context).highlightColor,
), ),
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.fromLTRB(16, 16, 8, 8),
child: stack, child: Column(
children: <Widget>[
top,
repoSelector,
],
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
),
);
if (!appSettings.proMode) {
return header;
}
return Banner(
message: tr('pro'),
location: BannerLocation.topStart,
color: Theme.of(context).accentColor,
child: header,
); );
} }
} }