✨ Customizable fab location
This commit is contained in:
@@ -422,6 +422,48 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
),
|
||||
),
|
||||
|
||||
// FAB position settings
|
||||
ListTile(
|
||||
minLeadingWidth: 48,
|
||||
title: Text('fabPosition').tr(),
|
||||
contentPadding: const EdgeInsets.only(left: 24, right: 17),
|
||||
leading: const Icon(Symbols.adjust),
|
||||
trailing: DropdownButtonHideUnderline(
|
||||
child: DropdownButton2<String>(
|
||||
isExpanded: true,
|
||||
items: [
|
||||
DropdownMenuItem<String>(
|
||||
value: 'left',
|
||||
child: Text('Left').fontSize(14),
|
||||
),
|
||||
DropdownMenuItem<String>(
|
||||
value: 'center',
|
||||
child: Text('Center').fontSize(14),
|
||||
),
|
||||
DropdownMenuItem<String>(
|
||||
value: 'right',
|
||||
child: Text('Right').fontSize(14),
|
||||
),
|
||||
],
|
||||
value: settings.fabPosition,
|
||||
onChanged: (String? value) {
|
||||
if (value != null) {
|
||||
ref
|
||||
.read(appSettingsNotifierProvider.notifier)
|
||||
.setFabPosition(value);
|
||||
showSnackBar('settingsApplied'.tr());
|
||||
}
|
||||
},
|
||||
buttonStyleData: const ButtonStyleData(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 5),
|
||||
height: 40,
|
||||
width: 120,
|
||||
),
|
||||
menuItemStyleData: const MenuItemStyleData(height: 40),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Card background opacity settings
|
||||
ListTile(
|
||||
minLeadingWidth: 48,
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:island/widgets/navigation/conditional_bottom_nav.dart';
|
||||
import 'package:island/widgets/navigation/fab_menu.dart';
|
||||
import 'package:material_symbols_icons/symbols.dart';
|
||||
import 'package:styled_widget/styled_widget.dart';
|
||||
import 'package:island/pods/config.dart';
|
||||
|
||||
final currentRouteProvider = StateProvider<String?>((ref) => null);
|
||||
|
||||
@@ -101,6 +102,7 @@ class TabsScreen extends HookConsumerWidget {
|
||||
isWideScreen(context) ? null : kWideScreenRouteStart,
|
||||
);
|
||||
final shouldShowFab = routes.contains(currentLocation) && !wideScreen;
|
||||
final settings = ref.watch(appSettingsNotifierProvider);
|
||||
|
||||
if (isWideScreen(context)) {
|
||||
return Container(
|
||||
@@ -151,7 +153,9 @@ class TabsScreen extends HookConsumerWidget {
|
||||
),
|
||||
floatingActionButton: shouldShowFab ? const FabMenu() : null,
|
||||
floatingActionButtonLocation:
|
||||
shouldShowFab ? _DockedFabLocation(context) : null,
|
||||
shouldShowFab
|
||||
? _DockedFabLocation(context, settings.fabPosition)
|
||||
: null,
|
||||
bottomNavigationBar: ConditionalBottomNav(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.only(
|
||||
@@ -189,9 +193,18 @@ class TabsScreen extends HookConsumerWidget {
|
||||
: null,
|
||||
);
|
||||
}).toList();
|
||||
// Add mock item in the center to leave space for FAB
|
||||
int centerIndex = navItems.length ~/ 2;
|
||||
navItems.insert(centerIndex, const SizedBox(width: 72));
|
||||
// Add mock item to leave space for FAB based on position
|
||||
final gapIndex = switch (settings.fabPosition) {
|
||||
'left' => 0,
|
||||
'right' => navItems.length,
|
||||
_ => navItems.length ~/ 2, // center
|
||||
};
|
||||
navItems.insert(
|
||||
gapIndex,
|
||||
SizedBox(
|
||||
width: settings.fabPosition == 'center' ? 72 : 48,
|
||||
),
|
||||
);
|
||||
return navItems;
|
||||
}(),
|
||||
),
|
||||
@@ -206,19 +219,28 @@ class TabsScreen extends HookConsumerWidget {
|
||||
|
||||
class _DockedFabLocation extends FloatingActionButtonLocation {
|
||||
final BuildContext context;
|
||||
final String fabPosition;
|
||||
|
||||
const _DockedFabLocation(this.context);
|
||||
const _DockedFabLocation(this.context, this.fabPosition);
|
||||
|
||||
@override
|
||||
Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
|
||||
final mediaQuery = MediaQuery.of(context);
|
||||
final safeAreaPadding = mediaQuery.padding;
|
||||
|
||||
// Center horizontally
|
||||
final double fabX =
|
||||
// Position horizontally based on setting
|
||||
final double fabX = switch (fabPosition) {
|
||||
'left' => scaffoldGeometry.minInsets.left + 24,
|
||||
'right' =>
|
||||
scaffoldGeometry.scaffoldSize.width -
|
||||
scaffoldGeometry.floatingActionButtonSize.width -
|
||||
scaffoldGeometry.minInsets.right -
|
||||
24,
|
||||
_ =>
|
||||
(scaffoldGeometry.scaffoldSize.width -
|
||||
scaffoldGeometry.floatingActionButtonSize.width) /
|
||||
2;
|
||||
scaffoldGeometry.floatingActionButtonSize.width) /
|
||||
2, // center
|
||||
};
|
||||
|
||||
// Position closer to bottom with reduced padding
|
||||
final double fabY =
|
||||
|
||||
Reference in New Issue
Block a user