ente/lib/ui/collections/button/uncategorized_button.dart

114 lines
4 KiB
Dart
Raw Normal View History

import 'package:collection/collection.dart';
2022-12-26 05:31:32 +00:00
import 'package:flutter/material.dart';
2023-04-05 09:50:48 +00:00
import "package:photos/generated/l10n.dart";
2023-08-25 04:39:30 +00:00
import 'package:photos/models/collection/collection.dart';
import 'package:photos/services/collections_service.dart';
import 'package:photos/services/hidden_service.dart';
import 'package:photos/ui/viewer/gallery/uncategorized_page.dart';
import 'package:photos/utils/navigation_util.dart';
2022-12-26 05:31:32 +00:00
2023-06-06 16:43:32 +00:00
class UnCategorizedCollections extends StatelessWidget {
2022-12-26 05:31:32 +00:00
final TextStyle textStyle;
2023-06-06 16:43:32 +00:00
const UnCategorizedCollections(
2022-12-26 05:31:32 +00:00
this.textStyle, {
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final Collection? collection = CollectionsService.instance
.getActiveCollections()
.firstWhereOrNull((e) => e.type == CollectionType.uncategorized);
if (collection == null) {
// create uncategorized collection if it's not already created
CollectionsService.instance.getUncategorizedCollection().ignore();
}
2022-12-26 05:31:32 +00:00
return OutlinedButton(
style: OutlinedButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.background,
2022-12-26 05:31:32 +00:00
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.all(0),
side: BorderSide(
width: 0.5,
color: Theme.of(context).iconTheme.color!.withOpacity(0.24),
),
),
child: SizedBox(
height: 48,
width: double.infinity,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(
Icons.category_outlined,
color: Theme.of(context).iconTheme.color,
),
const Padding(padding: EdgeInsets.all(6)),
FutureBuilder<int>(
future: collection == null
? Future.value(0)
2023-07-06 07:59:31 +00:00
: CollectionsService.instance.getFileCount(collection),
2022-12-26 05:31:32 +00:00
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data! > 0) {
return RichText(
text: TextSpan(
style: textStyle,
children: [
TextSpan(
2023-04-05 09:50:48 +00:00
text: S.of(context).uncategorized,
2023-06-13 06:41:31 +00:00
style: Theme.of(context).textTheme.titleMedium,
2022-12-26 05:31:32 +00:00
),
const TextSpan(text: " \u2022 "),
TextSpan(
text: snapshot.data.toString(),
),
//need to query in db and bring this value
],
),
);
} else {
return RichText(
text: TextSpan(
style: textStyle,
children: [
TextSpan(
2023-04-05 09:50:48 +00:00
text: S.of(context).uncategorized,
2023-06-13 06:41:31 +00:00
style: Theme.of(context).textTheme.titleMedium,
2022-12-26 05:31:32 +00:00
),
//need to query in db and bring this value
],
),
);
}
},
),
],
),
Icon(
Icons.chevron_right,
color: Theme.of(context).iconTheme.color,
),
],
),
),
),
onPressed: () async {
if (collection != null) {
2023-12-21 07:34:06 +00:00
// ignore: unawaited_futures
routeToPage(
context,
UnCategorizedPage(collection),
);
}
},
2022-12-26 05:31:32 +00:00
);
}
}