Skip to content

Commit

Permalink
feat: new option to move the floating action button to the left or ri…
Browse files Browse the repository at this point in the history
…ght of the screen
  • Loading branch information
David Welsh committed Nov 18, 2024
1 parent 7e6d2ac commit 5f15082
Show file tree
Hide file tree
Showing 20 changed files with 227 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/features/dashboard/account_list_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:kibisis/constants/constants.dart';
import 'package:kibisis/features/setup_account/add_account/add_account_body.dart';
import 'package:kibisis/generated/l10n.dart';
import 'package:kibisis/providers/accounts_list_provider.dart';
import 'package:kibisis/providers/fab_provider.dart';
import 'package:kibisis/providers/loading_provider.dart';
import 'package:kibisis/providers/setup_complete_provider.dart';
import 'package:kibisis/theme/color_palette.dart';
Expand All @@ -33,7 +34,7 @@ class AccountListScreenState extends ConsumerState<AccountListScreen> {
final accountsListState = ref.watch(accountsListProvider);
final isSetupComplete = ref.watch(setupCompleteProvider);
final flex = mediaQueryHelper.getDynamicFlex();

final fabPosition = ref.watch(fabPositionProvider);
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
Expand Down Expand Up @@ -72,7 +73,9 @@ class AccountListScreenState extends ConsumerState<AccountListScreen> {
backgroundColor: context.colorScheme.secondary,
child: const Icon(AppIcons.add),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
floatingActionButtonLocation: fabPosition == FabPosition.left
? FloatingActionButtonLocation.startFloat
: FloatingActionButtonLocation.endFloat,
);
}

Expand Down
7 changes: 5 additions & 2 deletions lib/features/dashboard/dashboard_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:kibisis/generated/l10n.dart';
import 'package:kibisis/models/select_item.dart';
import 'package:kibisis/providers/account_provider.dart';
import 'package:kibisis/providers/balance_provider.dart';
import 'package:kibisis/providers/fab_provider.dart';
import 'package:kibisis/providers/minimum_balance_provider.dart';
import 'package:kibisis/providers/network_provider.dart';
import 'package:kibisis/routing/named_routes.dart';
Expand Down Expand Up @@ -178,12 +179,14 @@ class DashboardScreenState extends ConsumerState<DashboardScreen> {
future: ref.read(accountProvider.notifier).hasPrivateKey(),
builder: (context, snapshot) {
final hasPrivateKey = snapshot.data ?? false;

final fabPosition = ref.watch(fabPositionProvider);
return ExpandableFab(
key: _key,
type: ExpandableFabType.up,
distance: 70,
pos: ExpandableFabPos.right,
pos: fabPosition == FabPosition.left
? ExpandableFabPos.left
: ExpandableFabPos.right,
onOpen: () => _handleVibration(kHapticButtonPressDuration),
overlayStyle: const ExpandableFabOverlayStyle(
color: Colors.black54,
Expand Down
61 changes: 61 additions & 0 deletions lib/features/settings/general/general_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:kibisis/common_widgets/confirmation_dialog.dart';
import 'package:kibisis/common_widgets/custom_bottom_sheet.dart';
import 'package:kibisis/common_widgets/custom_button.dart';
import 'package:kibisis/common_widgets/custom_dropdown.dart';
import 'package:kibisis/common_widgets/language_picker.dart';
import 'package:kibisis/common_widgets/pin_pad_dialog.dart';
import 'package:kibisis/common_widgets/top_snack_bar.dart';
import 'package:kibisis/constants/constants.dart';
import 'package:kibisis/generated/l10n.dart';
import 'package:kibisis/models/select_item.dart';
import 'package:kibisis/providers/fab_provider.dart';
import 'package:kibisis/providers/loading_provider.dart';
import 'package:kibisis/utils/app_icons.dart';
import 'package:kibisis/utils/app_reset_util.dart';
import 'package:kibisis/utils/theme_extensions.dart';

Expand All @@ -28,6 +33,8 @@ class GeneralScreen extends ConsumerWidget {
const SizedBox(height: kScreenPadding),
const LanguagePicker(),
const SizedBox(height: kScreenPadding),
_buildFabPositionSelector(context, ref),
const SizedBox(height: kScreenPadding),
_buildDangerZoneTitle(context),
const SizedBox(height: kScreenPadding / 2),
_buildDangerZoneDescription(context),
Expand Down Expand Up @@ -113,4 +120,58 @@ class GeneralScreen extends ConsumerWidget {
),
);
}

Widget _buildFabPositionSelector(BuildContext context, WidgetRef ref) {
final fabPosition = ref.watch(fabPositionProvider);
final List<SelectItem> positionList = [
SelectItem(
name: S.of(context).fabLeft,
value: FabPosition.left.name,
icon: SizedBox(
width: kScreenPadding * 1.5,
height: kScreenPadding * 1.5,
child: Transform(
alignment: Alignment.center,
transform: Matrix4.identity()..scale(-1.0, 1.0, 1.0),
child: const Icon(AppIcons.menuArrow),
),
),
),
SelectItem(
name: S.of(context).fabRight,
value: FabPosition.right.name,
icon: const Icon(AppIcons.menuArrow),
),
];

final selectedItem = positionList.firstWhere(
(item) => item.value == fabPosition.name,
orElse: () => positionList.first,
);

return GestureDetector(
onTap: () {
customBottomSheet(
context: context,
items: positionList,
header: S.of(context).fabPosition,
onPressed: (SelectItem selectedItem) {
final position = FabPosition.values.firstWhere(
(e) => e.name == selectedItem.value,
);
ref.read(fabPositionProvider.notifier).setPosition(position);
},
);
},
child: AbsorbPointer(
absorbing: true,
child: CustomDropDown(
label: S.of(context).fabPosition,
items: positionList,
selectedValue: selectedItem,
onChanged: null,
),
),
);
}
}
6 changes: 5 additions & 1 deletion lib/features/settings/sessions/sessions_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:intl/intl.dart';
import 'package:kibisis/common_widgets/confirmation_dialog.dart';
import 'package:kibisis/constants/constants.dart';
import 'package:kibisis/generated/l10n.dart';
import 'package:kibisis/providers/fab_provider.dart';
import 'package:kibisis/providers/storage_provider.dart';
import 'package:kibisis/utils/app_icons.dart';
import 'package:kibisis/utils/theme_extensions.dart';
Expand Down Expand Up @@ -168,7 +169,7 @@ class SessionsScreenState extends ConsumerState<SessionsScreen> {
@override
Widget build(BuildContext context) {
final accountsState = ref.watch(accountsListProvider);

final fabPosition = ref.watch(fabPositionProvider);
return Scaffold(
appBar: AppBar(
title: Text(SessionsScreen.title),
Expand Down Expand Up @@ -245,6 +246,9 @@ class SessionsScreenState extends ConsumerState<SessionsScreen> {
foregroundColor: Colors.white,
child: const Icon(AppIcons.scan),
),
floatingActionButtonLocation: fabPosition == FabPosition.left
? FloatingActionButtonLocation.startFloat
: FloatingActionButtonLocation.endFloat,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';
import 'package:kibisis/constants/constants.dart';
import 'package:kibisis/features/setup_account/add_account/add_account_body.dart';
import 'package:kibisis/generated/l10n.dart';
import 'package:kibisis/providers/fab_provider.dart';
import 'package:kibisis/providers/setup_complete_provider.dart';
import 'package:kibisis/utils/app_icons.dart';
import 'package:kibisis/utils/media_query_helper.dart';
Expand All @@ -24,7 +25,7 @@ class AddAccountScreenState extends ConsumerState<AddAccountScreen> {
Widget build(BuildContext context) {
final mediaQueryHelper = MediaQueryHelper(context);
final isSetupComplete = ref.watch(setupCompleteProvider);

final fabPosition = ref.watch(fabPositionProvider);
return Scaffold(
appBar: AppBar(
title: Text(AddAccountScreen.title),
Expand Down Expand Up @@ -65,6 +66,9 @@ class AddAccountScreenState extends ConsumerState<AddAccountScreen> {
child: const Icon(AppIcons.add),
)
: null,
floatingActionButtonLocation: fabPosition == FabPosition.left
? FloatingActionButtonLocation.startFloat
: FloatingActionButtonLocation.endFloat,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ class NameAccountScreenState extends ConsumerState<NameAccountScreen> {
),
),
),
floatingActionButton: _buildSubmitButton(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: _buildSubmitButton(),
);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ class MessageLookup extends MessageLookupByLibrary {
"expires": MessageLookupByLibrary.simpleMessage("Expires:"),
"exportAccounts":
MessageLookupByLibrary.simpleMessage("Export Accounts"),
"fabLeft": MessageLookupByLibrary.simpleMessage("Left"),
"fabPosition":
MessageLookupByLibrary.simpleMessage("Floating Button Position"),
"fabRight": MessageLookupByLibrary.simpleMessage("Right"),
"failedFinalizeAccountImport": MessageLookupByLibrary.simpleMessage(
"Failed to finalize account import."),
"failedParseWalletConnectUri": MessageLookupByLibrary.simpleMessage(
Expand Down
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ class MessageLookup extends MessageLookupByLibrary {
"expires": MessageLookupByLibrary.simpleMessage("Expira:"),
"exportAccounts":
MessageLookupByLibrary.simpleMessage("Exportar Cuentas"),
"fabLeft": MessageLookupByLibrary.simpleMessage("Izquierda"),
"fabPosition":
MessageLookupByLibrary.simpleMessage("Posición del Botón Flotante"),
"fabRight": MessageLookupByLibrary.simpleMessage("Derecha"),
"failedFinalizeAccountImport": MessageLookupByLibrary.simpleMessage(
"Error al finalizar la importación de la cuenta."),
"failedParseWalletConnectUri": MessageLookupByLibrary.simpleMessage(
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/intl/messages_th.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ class MessageLookup extends MessageLookupByLibrary {
"คาดหวังรหัส QR คีย์ส่วนตัวแต่พบ WalletConnect URI"),
"expires": MessageLookupByLibrary.simpleMessage("หมดอายุ:"),
"exportAccounts": MessageLookupByLibrary.simpleMessage("ส่งออกบัญชี"),
"fabLeft": MessageLookupByLibrary.simpleMessage("ซ้าย"),
"fabPosition": MessageLookupByLibrary.simpleMessage("ตำแหน่งปุ่มลอย"),
"fabRight": MessageLookupByLibrary.simpleMessage("ขวา"),
"failedFinalizeAccountImport":
MessageLookupByLibrary.simpleMessage("การนำเข้าบัญชีล้มเหลว"),
"failedParseWalletConnectUri": MessageLookupByLibrary.simpleMessage(
Expand Down
4 changes: 4 additions & 0 deletions lib/generated/intl/messages_tr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ class MessageLookup extends MessageLookupByLibrary {
"expires": MessageLookupByLibrary.simpleMessage("Son Kullanma Tarihi:"),
"exportAccounts":
MessageLookupByLibrary.simpleMessage("Hesapları Dışa Aktar"),
"fabLeft": MessageLookupByLibrary.simpleMessage("Sol"),
"fabPosition":
MessageLookupByLibrary.simpleMessage("Yüzen Düğme Konumu"),
"fabRight": MessageLookupByLibrary.simpleMessage("Sağ"),
"failedFinalizeAccountImport": MessageLookupByLibrary.simpleMessage(
"Hesap aktarımı tamamlanamadı."),
"failedParseWalletConnectUri": MessageLookupByLibrary.simpleMessage(
Expand Down
3 changes: 3 additions & 0 deletions lib/generated/intl/messages_vi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ class MessageLookup extends MessageLookupByLibrary {
"expires": MessageLookupByLibrary.simpleMessage("Hết hạn:"),
"exportAccounts":
MessageLookupByLibrary.simpleMessage("Xuất tài khoản"),
"fabLeft": MessageLookupByLibrary.simpleMessage("Trái"),
"fabPosition": MessageLookupByLibrary.simpleMessage("Vị Trí Nút Nổi"),
"fabRight": MessageLookupByLibrary.simpleMessage("Phải"),
"failedFinalizeAccountImport": MessageLookupByLibrary.simpleMessage(
"Không thể hoàn tất nhập tài khoản."),
"failedParseWalletConnectUri": MessageLookupByLibrary.simpleMessage(
Expand Down
31 changes: 31 additions & 0 deletions lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1876,6 +1876,18 @@
"viewSeedPhrase": "View Seed Phrase",
"@viewSeedPhrase": {
"description": "Label for the button or screen title to view the seed phrase."
},
"fabPosition": "Floating Button Position",
"@fabPosition": {
"description": "Label for the setting to choose the position of the floating action button."
},
"fabLeft": "Left",
"@fabLeft": {
"description": "Option for positioning the floating button on the left."
},
"fabRight": "Right",
"@fabRight": {
"description": "Option for positioning the floating button on the right."
}

}
13 changes: 13 additions & 0 deletions lib/l10n/intl_es.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,20 @@
"viewSeedPhrase": "Ver Frase Semilla",
"@viewSeedPhrase": {
"description": "Etiqueta para el botón o título de la pantalla para ver la frase semilla."
},
"fabPosition": "Posición del Botón Flotante",
"@fabPosition": {
"description": "Etiqueta para la configuración de la posición del botón de acción flotante."
},
"fabLeft": "Izquierda",
"@fabLeft": {
"description": "Opción para posicionar el botón flotante a la izquierda."
},
"fabRight": "Derecha",
"@fabRight": {
"description": "Opción para posicionar el botón flotante a la derecha."
}


}

12 changes: 12 additions & 0 deletions lib/l10n/intl_th.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,18 @@
"viewSeedPhrase": "ดูวลีสำรอง",
"@viewSeedPhrase": {
"description": "ป้ายกำกับสำหรับปุ่มหรือชื่อหน้าจอเพื่อดูวลีสำรอง"
},
"fabPosition": "ตำแหน่งปุ่มลอย",
"@fabPosition": {
"description": "ป้ายกำกับสำหรับการตั้งค่าเลือกตำแหน่งของปุ่มลอย."
},
"fabLeft": "ซ้าย",
"@fabLeft": {
"description": "ตัวเลือกสำหรับวางปุ่มลอยทางซ้าย."
},
"fabRight": "ขวา",
"@fabRight": {
"description": "ตัวเลือกสำหรับวางปุ่มลอยทางขวา."
}

}
13 changes: 13 additions & 0 deletions lib/l10n/intl_tr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,19 @@
"viewSeedPhrase": "Anahtar Cümlesini Görüntüle",
"@viewSeedPhrase": {
"description": "Anahtar cümlesini görüntülemek için düğme veya ekran başlığı etiketi."
},
"fabPosition": "Yüzen Düğme Konumu",
"@fabPosition": {
"description": "Yüzen işlem düğmesinin konumunu seçmek için ayar etiketi."
},
"fabLeft": "Sol",
"@fabLeft": {
"description": "Yüzen düğmenin sola yerleştirilmesi için seçenek."
},
"fabRight": "Sağ",
"@fabRight": {
"description": "Yüzen düğmenin sağa yerleştirilmesi için seçenek."
}


}
13 changes: 13 additions & 0 deletions lib/l10n/intl_vi.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1963,5 +1963,18 @@
"viewSeedPhrase": "Xem Cụm Từ Khóa",
"@viewSeedPhrase": {
"description": "Nhãn cho nút hoặc tiêu đề màn hình để xem cụm từ khóa."
},
"fabPosition": "Vị Trí Nút Nổi",
"@fabPosition": {
"description": "Nhãn cho cài đặt chọn vị trí của nút hành động nổi."
},
"fabLeft": "Trái",
"@fabLeft": {
"description": "Tùy chọn đặt nút nổi ở bên trái."
},
"fabRight": "Phải",
"@fabRight": {
"description": "Tùy chọn đặt nút nổi ở bên phải."
}

}
Loading

0 comments on commit 5f15082

Please sign in to comment.