selection: toggle section selection by tapping header
This commit is contained in:
parent
bcc571fa84
commit
2ed7851d7d
1 changed files with 44 additions and 33 deletions
|
@ -129,6 +129,8 @@ class TitleSectionHeader extends StatelessWidget {
|
||||||
alignment: AlignmentDirectional.centerStart,
|
alignment: AlignmentDirectional.centerStart,
|
||||||
padding: padding,
|
padding: padding,
|
||||||
constraints: const BoxConstraints(minHeight: leadingDimension),
|
constraints: const BoxConstraints(minHeight: leadingDimension),
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () => _toggleSectionSelection(context),
|
||||||
child: Text.rich(
|
child: Text.rich(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
children: [
|
||||||
|
@ -144,6 +146,7 @@ class TitleSectionHeader extends StatelessWidget {
|
||||||
child: leading,
|
child: leading,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
|
onPressed: () => _toggleSectionSelection(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextSpan(
|
TextSpan(
|
||||||
|
@ -161,18 +164,32 @@ class TitleSectionHeader extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _toggleSectionSelection(BuildContext context) {
|
||||||
|
final collection = Provider.of<CollectionLens>(context, listen: false);
|
||||||
|
final sectionEntries = collection.sections[sectionKey];
|
||||||
|
final selected = collection.isSelected(sectionEntries);
|
||||||
|
if (selected) {
|
||||||
|
collection.removeFromSelection(sectionEntries);
|
||||||
|
} else {
|
||||||
|
collection.addToSelection(sectionEntries);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SectionSelectableLeading extends StatelessWidget {
|
class SectionSelectableLeading extends StatelessWidget {
|
||||||
final dynamic sectionKey;
|
final dynamic sectionKey;
|
||||||
final WidgetBuilder browsingBuilder;
|
final WidgetBuilder browsingBuilder;
|
||||||
|
final VoidCallback onPressed;
|
||||||
|
|
||||||
const SectionSelectableLeading({
|
const SectionSelectableLeading({
|
||||||
Key key,
|
Key key,
|
||||||
@required this.sectionKey,
|
@required this.sectionKey,
|
||||||
@required this.browsingBuilder,
|
@required this.browsingBuilder,
|
||||||
|
@required this.onPressed,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
static const leadingDimension = TitleSectionHeader.leadingDimension;
|
static const leadingDimension = TitleSectionHeader.leadingDimension;
|
||||||
|
@ -199,13 +216,7 @@ class SectionSelectableLeading extends StatelessWidget {
|
||||||
padding: const EdgeInsets.only(top: 1),
|
padding: const EdgeInsets.only(top: 1),
|
||||||
alignment: Alignment.topLeft,
|
alignment: Alignment.topLeft,
|
||||||
icon: Icon(selected ? AIcons.selected : AIcons.unselected),
|
icon: Icon(selected ? AIcons.selected : AIcons.unselected),
|
||||||
onPressed: () {
|
onPressed: onPressed,
|
||||||
if (selected) {
|
|
||||||
collection.removeFromSelection(sectionEntries);
|
|
||||||
} else {
|
|
||||||
collection.addToSelection(sectionEntries);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
tooltip: selected ? 'Deselect section' : 'Select section',
|
tooltip: selected ? 'Deselect section' : 'Select section',
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
minHeight: leadingDimension,
|
minHeight: leadingDimension,
|
||||||
|
|
Loading…
Reference in a new issue