photoFileWidget method

Widget photoFileWidget(
  1. BuildContext context,
  2. bool isWide
)

Implementation

Widget photoFileWidget(BuildContext context, bool isWide) {
  // final privateFolderId = node.properties?['privateFolderId'];

  // Check if the name starts with a date in YYYY-MM-DD format or YYYY-MM-D.
  final String? dateMatch =
      RegExp(r'\d{4}-\d{1,2}-\d{1,2}').firstMatch(node.file.name!)?.group(0);
  String? date;
  if (dateMatch != null && dateMatch.split('-')[2].length == 1) {
    // Add a leading zero to the day if it is missing
    date =
        '${dateMatch.split('-')[0]}-${dateMatch.split('-')[1]}-0${dateMatch.split('-')[2]}';
  } else {
    date = dateMatch;
  }
  return Consumer(
    builder: (context, ref, _) {
      return Stack(
        children: [
          ListTile(
            title: Text.rich(
              TextSpan(
                children: [
                  if (date != null)
                    // Show the date in a readable format
                    TextSpan(
                      text: DateTime.parse(date).toFrontendDateFormatString(),
                      style: isWide
                          ? Theme.of(context).textTheme.labelMedium
                          : Theme.of(context).textTheme.labelSmall,
                    ),
                  TextSpan(
                    text:
                        " • ${node.numberOfChildren}${node.numberOfChildren == 100 ? '+' : ''} ${t.photos.photos}",
                    style: isWide
                        ? Theme.of(context).textTheme.labelMedium
                        : Theme.of(context).textTheme.labelSmall,
                  ),
                  if (date != null || node.numberOfChildren != null)
                    const TextSpan(text: "\n"),
                  // Show the name of the folder. Remove the date from the name
                  TextSpan(
                    text: node.file.name
                        ?.replaceAll(dateMatch ?? '', '')
                        .trim(),
                    style: Theme.of(context).textTheme.titleLarge,
                  ),
                ],
              ),
            ),
          ),
          // TODO: Implement photo upload
          // Positioned(
          //   right: 0,
          //   bottom: 0,
          //   child: Builder(
          //     builder: (context) {
          //       return TextButton.icon(
          //         icon: const Icon(Icons.upload_file),
          //         label: const Text("Upload"),
          //         onPressed: () {
          //           userPhotoUpload(context, ref, privateFolderId);
          //         },
          //       );
          //     },
          //   ),
          // ),
        ],
      );
    },
  );
}