mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Migrate buttons in HomeAlbum to m3 chips
This commit is contained in:
parent
0e31d2fb66
commit
8eaf1a7b7b
3 changed files with 97 additions and 43 deletions
|
@ -4,6 +4,7 @@ class M3 extends ThemeExtension<M3> {
|
||||||
const M3({
|
const M3({
|
||||||
required this.seed,
|
required this.seed,
|
||||||
required this.checkbox,
|
required this.checkbox,
|
||||||
|
required this.assistChip,
|
||||||
required this.filterChip,
|
required this.filterChip,
|
||||||
required this.listTile,
|
required this.listTile,
|
||||||
});
|
});
|
||||||
|
@ -14,12 +15,14 @@ class M3 extends ThemeExtension<M3> {
|
||||||
M3 copyWith({
|
M3 copyWith({
|
||||||
Color? seed,
|
Color? seed,
|
||||||
M3Checkbox? checkbox,
|
M3Checkbox? checkbox,
|
||||||
|
M3AssistChip? assistChip,
|
||||||
M3FilterChip? filterChip,
|
M3FilterChip? filterChip,
|
||||||
M3ListTile? listTile,
|
M3ListTile? listTile,
|
||||||
}) =>
|
}) =>
|
||||||
M3(
|
M3(
|
||||||
seed: seed ?? this.seed,
|
seed: seed ?? this.seed,
|
||||||
checkbox: checkbox ?? this.checkbox,
|
checkbox: checkbox ?? this.checkbox,
|
||||||
|
assistChip: assistChip ?? this.assistChip,
|
||||||
filterChip: filterChip ?? this.filterChip,
|
filterChip: filterChip ?? this.filterChip,
|
||||||
listTile: listTile ?? this.listTile,
|
listTile: listTile ?? this.listTile,
|
||||||
);
|
);
|
||||||
|
@ -32,6 +35,7 @@ class M3 extends ThemeExtension<M3> {
|
||||||
return M3(
|
return M3(
|
||||||
seed: Color.lerp(seed, other.seed, t)!,
|
seed: Color.lerp(seed, other.seed, t)!,
|
||||||
checkbox: checkbox.lerp(other.checkbox, t),
|
checkbox: checkbox.lerp(other.checkbox, t),
|
||||||
|
assistChip: assistChip.lerp(other.assistChip, t),
|
||||||
filterChip: filterChip.lerp(other.filterChip, t),
|
filterChip: filterChip.lerp(other.filterChip, t),
|
||||||
listTile: listTile.lerp(other.listTile, t),
|
listTile: listTile.lerp(other.listTile, t),
|
||||||
);
|
);
|
||||||
|
@ -39,6 +43,7 @@ class M3 extends ThemeExtension<M3> {
|
||||||
|
|
||||||
final Color seed;
|
final Color seed;
|
||||||
final M3Checkbox checkbox;
|
final M3Checkbox checkbox;
|
||||||
|
final M3AssistChip assistChip;
|
||||||
final M3FilterChip filterChip;
|
final M3FilterChip filterChip;
|
||||||
final M3ListTile listTile;
|
final M3ListTile listTile;
|
||||||
}
|
}
|
||||||
|
@ -77,6 +82,44 @@ class M3CheckboxDisabled {
|
||||||
final Color container;
|
final Color container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class M3AssistChip {
|
||||||
|
const M3AssistChip({
|
||||||
|
required this.enabled,
|
||||||
|
});
|
||||||
|
|
||||||
|
M3AssistChip lerp(M3AssistChip? other, double t) {
|
||||||
|
if (other is! M3AssistChip) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return M3AssistChip(
|
||||||
|
enabled: enabled.lerp(other.enabled, t),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final M3AssistChipEnabled enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
class M3AssistChipEnabled {
|
||||||
|
const M3AssistChipEnabled({
|
||||||
|
required this.container,
|
||||||
|
required this.containerElevated,
|
||||||
|
});
|
||||||
|
|
||||||
|
M3AssistChipEnabled lerp(M3AssistChipEnabled? other, double t) {
|
||||||
|
if (other is! M3AssistChipEnabled) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return M3AssistChipEnabled(
|
||||||
|
container: Color.lerp(container, other.container, t)!,
|
||||||
|
containerElevated:
|
||||||
|
Color.lerp(containerElevated, other.containerElevated, t)!,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Color container;
|
||||||
|
final Color containerElevated;
|
||||||
|
}
|
||||||
|
|
||||||
class M3FilterChip {
|
class M3FilterChip {
|
||||||
const M3FilterChip({
|
const M3FilterChip({
|
||||||
required this.disabled,
|
required this.disabled,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:logging/logging.dart';
|
|
||||||
import 'package:nc_photos/material3.dart';
|
import 'package:nc_photos/material3.dart';
|
||||||
import 'package:nc_photos/pref.dart';
|
import 'package:nc_photos/pref.dart';
|
||||||
|
|
||||||
|
@ -200,6 +199,12 @@ ThemeData _applyColorScheme(ColorScheme colorScheme, Color seedColor) {
|
||||||
container: colorScheme.onSurface.withOpacity(.38),
|
container: colorScheme.onSurface.withOpacity(.38),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
assistChip: M3AssistChip(
|
||||||
|
enabled: M3AssistChipEnabled(
|
||||||
|
container: Colors.transparent,
|
||||||
|
containerElevated: colorScheme.surface,
|
||||||
|
),
|
||||||
|
),
|
||||||
filterChip: M3FilterChip(
|
filterChip: M3FilterChip(
|
||||||
disabled: M3FilterChipDisabled(
|
disabled: M3FilterChipDisabled(
|
||||||
containerSelected: colorScheme.onSurface.withOpacity(.12),
|
containerSelected: colorScheme.onSurface.withOpacity(.12),
|
||||||
|
@ -216,5 +221,3 @@ ThemeData _applyColorScheme(ColorScheme colorScheme, Color seedColor) {
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final _log = Logger("theme");
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:ui';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
@ -17,6 +16,7 @@ import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/event/event.dart';
|
import 'package:nc_photos/event/event.dart';
|
||||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
|
import 'package:nc_photos/material3.dart';
|
||||||
import 'package:nc_photos/object_extension.dart';
|
import 'package:nc_photos/object_extension.dart';
|
||||||
import 'package:nc_photos/platform/features.dart' as features;
|
import 'package:nc_photos/platform/features.dart' as features;
|
||||||
import 'package:nc_photos/pref.dart';
|
import 'package:nc_photos/pref.dart';
|
||||||
|
@ -127,7 +127,6 @@ class _HomeAlbumsState extends State<HomeAlbums>
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
sliver: buildItemStreamList(
|
sliver: buildItemStreamList(
|
||||||
maxCrossAxisExtent: 256,
|
maxCrossAxisExtent: 256,
|
||||||
mainAxisSpacing: 6,
|
|
||||||
childBorderRadius: BorderRadius.zero,
|
childBorderRadius: BorderRadius.zero,
|
||||||
indicatorAlignment: const Alignment(-.92, -.92),
|
indicatorAlignment: const Alignment(-.92, -.92),
|
||||||
),
|
),
|
||||||
|
@ -540,44 +539,54 @@ class _ButtonListItem extends _ListItem {
|
||||||
get staggeredTile => const StaggeredTile.fit(1);
|
get staggeredTile => const StaggeredTile.fit(1);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
buildWidget(BuildContext context) {
|
Widget buildWidget(BuildContext context) => _ButtonListItemView(
|
||||||
return Padding(
|
icon: icon,
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
label: label,
|
||||||
child: ClipRRect(
|
onTap: _onTap,
|
||||||
borderRadius: BorderRadius.circular(8),
|
isShowIndicator: isShowIndicator,
|
||||||
child: Material(
|
);
|
||||||
type: MaterialType.transparency,
|
|
||||||
child: InkWell(
|
final IconData icon;
|
||||||
onTap: _onTap,
|
final String label;
|
||||||
child: Container(
|
final bool isShowIndicator;
|
||||||
decoration: BoxDecoration(
|
|
||||||
border: Border.all(
|
final VoidCallback? _onTap;
|
||||||
color: Theme.of(context).colorScheme.outline,
|
}
|
||||||
width: 1,
|
|
||||||
|
class _ButtonListItemView extends StatelessWidget {
|
||||||
|
const _ButtonListItemView({
|
||||||
|
required this.icon,
|
||||||
|
required this.label,
|
||||||
|
this.onTap,
|
||||||
|
this.isShowIndicator = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Theme(
|
||||||
|
data: Theme.of(context).copyWith(
|
||||||
|
canvasColor: M3.of(context).assistChip.enabled.container,
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
child: ActionChip(
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
labelPadding: const EdgeInsetsDirectional.fromSTEB(8, 0, 0, 0),
|
||||||
|
// specify icon size explicitly to workaround size flickering during
|
||||||
|
// theme transition
|
||||||
|
avatar: Icon(icon, size: 18),
|
||||||
|
label: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(child: Text(label)),
|
||||||
|
if (isShowIndicator)
|
||||||
|
Icon(
|
||||||
|
Icons.circle,
|
||||||
|
color: Theme.of(context).colorScheme.tertiary,
|
||||||
|
size: 8,
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(8),
|
],
|
||||||
),
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Icon(icon),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: Theme.of(context).textTheme.labelLarge,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (isShowIndicator)
|
|
||||||
Icon(
|
|
||||||
Icons.circle,
|
|
||||||
color: Theme.of(context).colorScheme.tertiary,
|
|
||||||
size: 8,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
onPressed: onTap,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -585,9 +594,8 @@ class _ButtonListItem extends _ListItem {
|
||||||
|
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String label;
|
final String label;
|
||||||
|
final VoidCallback? onTap;
|
||||||
final bool isShowIndicator;
|
final bool isShowIndicator;
|
||||||
|
|
||||||
final VoidCallback? _onTap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SeparatorListItem extends _ListItem {
|
class _SeparatorListItem extends _ListItem {
|
||||||
|
|
Loading…
Reference in a new issue