diff --git a/lib/controls/current_profile_button.dart b/lib/controls/current_profile_button.dart new file mode 100644 index 0000000..a44bb52 --- /dev/null +++ b/lib/controls/current_profile_button.dart @@ -0,0 +1,20 @@ +import 'package:cached_network_image/cached_network_image.dart'; +import 'package:flutter/material.dart'; + +import '../globals.dart'; +import '../services/auth_service.dart'; + +Widget? buildCurrentProfileButton(BuildContext context) { + final service = getIt(); + if (!service.loggedIn) { + return null; + } + + return Builder(builder: (context) { + return IconButton( + onPressed: () { + Scaffold.of(context).openDrawer(); + }, + icon: CachedNetworkImage(imageUrl: service.currentProfile.avatar)); + }); +} diff --git a/lib/controls/standard_appbar.dart b/lib/controls/standard_appbar.dart index e6acfbf..0df35e5 100644 --- a/lib/controls/standard_appbar.dart +++ b/lib/controls/standard_appbar.dart @@ -1,26 +1,12 @@ -import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; -import '../globals.dart'; -import '../services/auth_service.dart'; +import 'current_profile_button.dart'; class StandardAppBar { static AppBar build(BuildContext context, String title, {bool withDrawer = false, List? actions}) { - final service = getIt(); return AppBar( - leading: withDrawer - ? service.loggedIn - ? Builder(builder: (context) { - return IconButton( - onPressed: () { - Scaffold.of(context).openDrawer(); - }, - icon: CachedNetworkImage( - imageUrl: service.currentProfile.avatar)); - }) - : null - : null, + leading: withDrawer ? buildCurrentProfileButton(context) : null, title: Text( title, overflow: TextOverflow.ellipsis, diff --git a/lib/screens/contacts_screen.dart b/lib/screens/contacts_screen.dart index fa86e1e..b7fd272 100644 --- a/lib/screens/contacts_screen.dart +++ b/lib/screens/contacts_screen.dart @@ -2,9 +2,11 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:logging/logging.dart'; import 'package:provider/provider.dart'; +import 'package:relatica/controls/standard_app_drawer.dart'; import 'package:relatica/utils/active_profile_selector.dart'; import '../controls/app_bottom_nav_bar.dart'; +import '../controls/current_profile_button.dart'; import '../controls/padding.dart'; import '../controls/status_and_refresh_button.dart'; import '../globals.dart'; @@ -64,7 +66,9 @@ class _ContactsScreenState extends State { separatorBuilder: (context, index) => const Divider(), itemCount: contacts.length); } + final profileButton = buildCurrentProfileButton(context); return Scaffold( + drawer: StandardAppDrawer(), body: SafeArea( child: RefreshIndicator( onRefresh: () async { @@ -81,6 +85,10 @@ class _ContactsScreenState extends State { padding: const EdgeInsets.all(8.0), child: Row( children: [ + if (profileButton != null) ...[ + SizedBox(width: 70.0, child: profileButton), + const HorizontalPadding(), + ], Expanded( child: TextField( onChanged: (value) {