Files
social-app/apps/lib/shared/widgets/app_selection_sheet.dart
T

119 lines
3.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import '../../core/l10n/l10n.dart';
import '../../core/theme/design_tokens.dart';
import 'app_button.dart';
class AppSelectionItem<T> {
const AppSelectionItem({required this.value, required this.label});
final T value;
final String label;
}
Future<T?> showAppSelectionSheet<T>(
BuildContext context, {
required String title,
required List<AppSelectionItem<T>> items,
required T? selectedValue,
}) async {
final result = await showModalBottomSheet<T>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (sheetContext) {
return SafeArea(
top: false,
child: Container(
margin: const EdgeInsets.fromLTRB(
AppSpacing.md,
AppSpacing.none,
AppSpacing.md,
AppSpacing.md,
),
padding: const EdgeInsets.symmetric(vertical: AppSpacing.lg),
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(AppRadius.xl),
border: Border.all(color: AppColors.borderSecondary),
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.lg),
child: Text(
title,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 17,
fontWeight: FontWeight.w700,
color: AppColors.slate900,
),
),
),
const SizedBox(height: AppSpacing.md),
...items.map((item) {
final isSelected = item.value == selectedValue;
return _buildItem(
sheetContext,
item: item,
isSelected: isSelected,
);
}),
const SizedBox(height: AppSpacing.sm),
const Divider(height: 1, color: AppColors.border),
const SizedBox(height: AppSpacing.sm),
Padding(
padding: const EdgeInsets.symmetric(horizontal: AppSpacing.lg),
child: SizedBox(
height: 48,
child: AppButton(
text: context.l10n.commonCancel,
isOutlined: true,
onPressed: () => Navigator.of(sheetContext).pop(),
),
),
),
],
),
),
);
},
);
return result;
}
Widget _buildItem<T>(
BuildContext sheetContext, {
required AppSelectionItem<T> item,
required bool isSelected,
}) {
return InkWell(
onTap: () => Navigator.of(sheetContext).pop(item.value),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.lg,
vertical: AppSpacing.md,
),
child: Row(
children: [
Expanded(
child: Text(
item.label,
style: TextStyle(
fontSize: 15,
fontWeight: isSelected ? FontWeight.w600 : FontWeight.w500,
color: isSelected ? AppColors.blue600 : AppColors.slate800,
),
),
),
if (isSelected)
const Icon(Icons.check, size: 20, color: AppColors.blue600),
],
),
),
);
}