Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 4387b88d4dfddf360388490fa92ca628d37f317c

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
38 changes: 37 additions & 1 deletion lib/use_case/selection/core/custom_selection_demo_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:kartal/kartal.dart';
import 'package:use_case_flutter/use_case/selection/core/custom_selection_sheet.dart';
import 'package:use_case_flutter/use_case/selection/core/model/product_model.dart';
import 'package:use_case_flutter/use_case/selection/core/model/product_model_factory.dart';
Expand All @@ -25,7 +26,12 @@ class _CustomSelectionDemoViewState extends State<CustomSelectionDemoView> {
final response = await CustomSelectionSheet.show<ProductModel>(
context,
items: ProductModelFactory.shopItems().items,
selected: _productModelNotifier.value,
builder: (BuildContext context, ProductModel item) {
return _SelectionItem(
productModel: item,
isSelected: _productModelNotifier.value == item,
);
},
);
_productModelNotifier.value = response;
},
Expand All @@ -40,3 +46,33 @@ class _CustomSelectionDemoViewState extends State<CustomSelectionDemoView> {
);
}
}

/// A widget that displays a selection item.
/// [isSelected] is used to determine if the selection is selected.
/// [productModel] is the product model to display.
final class _SelectionItem extends StatelessWidget {
const _SelectionItem({
required this.productModel,
required this.isSelected,
});

final ProductModel productModel;
final bool isSelected;

@override
Widget build(BuildContext context) {
return ListTile(
onTap: () {
Navigator.pop(context, productModel);
},
title: Text(productModel.name),
subtitle: Text(productModel.price.toString()).ext.toVisible(
value: productModel.price > 100,
),
leading: Icon(
Icons.check_circle,
color: isSelected ? Colors.green : Colors.grey,
),
);
}
}
41 changes: 23 additions & 18 deletions lib/use_case/selection/core/custom_selection_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,39 @@ import 'package:flutter/material.dart';
import 'package:kartal/kartal.dart';
import 'package:use_case_flutter/use_case/selection/core/custom_selection_abstract.dart';

/// A builder that builds a widget for a given item.
typedef SelectionWidgetBuilder<T> = Widget Function(
BuildContext context,
T item,
);

/// A sheet that allows the user to select a custom selection.
/// [isSelected] is used to determine if the selection is selected.
final class CustomSelectionSheet<T extends CustomSelectionAbstract>
extends StatelessWidget {
const CustomSelectionSheet._({
required this.items,
required this.selected,
required this.builder,
super.key,
});

/// Shows the custom selection sheet.
static Future<T?> show<T extends CustomSelectionAbstract>(
BuildContext context, {
required List<T> items,
required T? selected,
required SelectionWidgetBuilder<T> builder,
}) {
return showModalBottomSheet<T?>(
context: context,
builder: (context) => CustomSelectionSheet._(
items: items,
selected: selected,
builder: builder,
),
);
}

final List<T> items;
final T? selected;
final SelectionWidgetBuilder<T> builder;

@override
Widget build(BuildContext context) {
Expand All @@ -41,27 +47,26 @@ final class CustomSelectionSheet<T extends CustomSelectionAbstract>
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
final selection = items[index];
return ListTile(
onTap: () {
Navigator.pop(context, selection);
},
title: Text(selection.name),
leading: Icon(
Icons.check_circle,
color: selected == selection ? Colors.green : Colors.grey,
),
);
return builder(context, selection);
// return ListTile(
// onTap: () {
// Navigator.pop(context, selection);
// },
// title: Text(selection.name),
// leading: Icon(
// Icons.check_circle,
// color: selected == selection ? Colors.green : Colors.grey,
// ),
// );
},
),
],
);
}
}

class _Notch extends StatelessWidget {
const _Notch({
super.key,
});
final class _Notch extends StatelessWidget {
const _Notch();

@override
Widget build(BuildContext context) {
Expand Down
4 changes: 2 additions & 2 deletions module/codegen/android/local.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sdk.dir=/Users/vb10/Library/Android/sdk
flutter.sdk=/Users/vb10/development/flutter
sdk.dir=/Users/burak/Library/Android/sdk
flutter.sdk=/Users/burak/fvm/versions/stable