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
21 changes: 16 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:pluto_grid/pluto_grid.dart';

Expand Down Expand Up @@ -50,11 +52,20 @@ class _PlutoGridExamplePageState extends State<PlutoGridExamplePage> {
PlutoColumn(
title: 'Role',
field: 'role',
type: PlutoColumnType.select(<String>[
'Programmer',
'Designer',
'Owner',
]),
type: PlutoColumnType.select(
<String>[
'Programmer',
'Designer',
'Owner',
],
onItemSelected: (PlutoGridOnSelectedEvent event) {
if (event.cell!.value == "Programmer") {
print("Hello Programmer");
} else {
print("Hello Developer");
}
},
),
),
PlutoColumn(
title: 'Joined',
Expand Down
13 changes: 13 additions & 0 deletions lib/src/model/pluto_column_type.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart' as intl;
import 'package:pluto_grid/pluto_grid.dart';

abstract class PlutoColumnType {
dynamic get defaultValue;
Expand Down Expand Up @@ -87,17 +88,26 @@ abstract class PlutoColumnType {

/// Provides a selection list and sets it as a selection column.
///
///The function[onItemSelected] is callback function, which is called
///when selecting an item from the items list.
///
///when selecting an item the [onItemSelected] function will be called
///immediately and it return [PlutoGridOnSelectedEvent] event, so you
///you can use it make decisions.
///
/// If [enableColumnFilter] is true, column filtering is enabled in the selection popup.
///
/// Set the suffixIcon in the [popupIcon] cell. Tapping this icon will open a selection popup.
/// The default icon is displayed, and if this value is set to null , the icon does not appear.
factory PlutoColumnType.select(
List<dynamic> items, {
final Function(PlutoGridOnSelectedEvent event)? onItemSelected,
dynamic defaultValue = '',
bool enableColumnFilter = false,
IconData? popupIcon = Icons.arrow_drop_down,
}) {
return PlutoColumnTypeSelect(
onItemSelected: onItemSelected ?? (event) {},
defaultValue: defaultValue,
items: items,
enableColumnFilter: enableColumnFilter,
Expand Down Expand Up @@ -360,10 +370,13 @@ class PlutoColumnTypeSelect

final bool enableColumnFilter;

final Function(PlutoGridOnSelectedEvent event) onItemSelected;

@override
final IconData? popupIcon;

const PlutoColumnTypeSelect({
required this.onItemSelected,
this.defaultValue,
required this.items,
required this.enableColumnFilter,
Expand Down
6 changes: 6 additions & 0 deletions lib/src/ui/cells/pluto_select_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class PlutoSelectCellState extends State<PlutoSelectCell>
}).toList();
}

@override
void onSelected(PlutoGridOnSelectedEvent event) {
widget.column.type.select.onItemSelected(event);
super.onSelected(event);
}

@override
void onLoaded(PlutoGridOnLoadedEvent event) {
super.onLoaded(event);
Expand Down