fix: #509 enable select on tag

This commit is contained in:
appflowy 2022-05-30 10:42:30 +08:00
parent 5da8144456
commit 546b1d22f4
2 changed files with 20 additions and 14 deletions

View File

@ -1,6 +1,7 @@
import 'package:flowy_infra/theme.dart'; import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart'; import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/style_widget/text.dart'; import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart'; import 'package:flowy_sdk/protobuf/flowy-grid/selection_type_option.pb.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
@ -64,9 +65,11 @@ class SelectOptionTag extends StatelessWidget {
final String name; final String name;
final Color color; final Color color;
final bool isSelected; final bool isSelected;
final VoidCallback? onSelected;
const SelectOptionTag({ const SelectOptionTag({
required this.name, required this.name,
required this.color, required this.color,
this.onSelected,
this.isSelected = false, this.isSelected = false,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -74,12 +77,14 @@ class SelectOptionTag extends StatelessWidget {
factory SelectOptionTag.fromSelectOption({ factory SelectOptionTag.fromSelectOption({
required BuildContext context, required BuildContext context,
required SelectOption option, required SelectOption option,
VoidCallback? onSelected,
bool isSelected = false, bool isSelected = false,
}) { }) {
return SelectOptionTag( return SelectOptionTag(
name: option.name, name: option.name,
color: option.color.make(context), color: option.color.make(context),
isSelected: isSelected, isSelected: isSelected,
onSelected: onSelected,
); );
} }
@ -92,19 +97,12 @@ class SelectOptionTag extends StatelessWidget {
backgroundColor: color, backgroundColor: color,
labelPadding: const EdgeInsets.symmetric(horizontal: 6), labelPadding: const EdgeInsets.symmetric(horizontal: 6),
selected: true, selected: true,
onSelected: (_) {}, onSelected: (_) {
if (onSelected != null) {
onSelected!();
}
},
); );
// return Container(
// decoration: BoxDecoration(
// color: option.color.make(context),
// shape: BoxShape.rectangle,
// borderRadius: BorderRadius.circular(8.0),
// ),
// child: Center(child: FlowyText.medium(option.name, fontSize: 12)),
// margin: const EdgeInsets.symmetric(horizontal: 3.0),
// padding: const EdgeInsets.symmetric(horizontal: 6.0),
// );
} }
} }
@ -136,7 +134,11 @@ class SelectOptionTagCell extends StatelessWidget {
Flexible( Flexible(
fit: FlexFit.loose, fit: FlexFit.loose,
flex: 2, flex: 2,
child: SelectOptionTag.fromSelectOption(context: context, option: option), child: SelectOptionTag.fromSelectOption(
context: context,
option: option,
onSelected: () => onSelected(option),
),
), ),
const Spacer(), const Spacer(),
...children, ...children,

View File

@ -233,7 +233,11 @@ class _SelectOptionCell extends StatelessWidget {
context.read<SelectOptionCellEditorBloc>().add(SelectOptionEditorEvent.selectOption(option.id)); context.read<SelectOptionCellEditorBloc>().add(SelectOptionEditorEvent.selectOption(option.id));
}, },
children: [ children: [
if (isSelected) svgWidget("grid/checkmark"), if (isSelected)
Padding(
padding: const EdgeInsets.only(right: 6),
child: svgWidget("grid/checkmark"),
),
], ],
), ),
), ),