浏览代码

added actionIcons property to TitleBarWidget

ashilkn 2 年之前
父节点
当前提交
b3881b30c4
共有 1 个文件被更改,包括 30 次插入23 次删除
  1. 30 23
      lib/ui/components/title_bar_widget.dart

+ 30 - 23
lib/ui/components/title_bar_widget.dart

@@ -2,7 +2,8 @@ import 'package:flutter/material.dart';
 import 'package:photos/theme/ente_theme.dart';
 
 class TitleBarWidget extends StatelessWidget {
-  const TitleBarWidget({super.key});
+  final List<Widget>? actionIcons;
+  const TitleBarWidget({this.actionIcons, super.key});
 
   @override
   Widget build(BuildContext context) {
@@ -34,31 +35,10 @@ class TitleBarWidget extends StatelessWidget {
         Padding(
           padding: const EdgeInsets.fromLTRB(4, 4, 12, 4),
           child: Row(
-            children: [
-              IconButton(
-                visualDensity:
-                    const VisualDensity(horizontal: -2, vertical: -2),
-                onPressed: () {},
-                icon: Icon(
-                  Icons.favorite_border_rounded,
-                  color: getEnteColorScheme(context).strokeBase,
-                ),
-              ),
-              const SizedBox(width: 4),
-              IconButton(
-                visualDensity:
-                    const VisualDensity(horizontal: -2, vertical: -2),
-                onPressed: () {},
-                icon: Icon(
-                  Icons.more_horiz_outlined,
-                  color: getEnteColorScheme(context).strokeBase,
-                ),
-              ),
-            ],
+            children: _getActions(),
           ),
         ),
       ],
-      // iconTheme:
       leading: Padding(
         padding: const EdgeInsets.all(4),
         child: IconButton(
@@ -93,4 +73,31 @@ class TitleBarWidget extends StatelessWidget {
       ),
     );
   }
+
+  _getActions() {
+    if (actionIcons == null) {
+      return <Widget>[const SizedBox.shrink()];
+    }
+    final actions = <Widget>[];
+    bool addWhiteSpace = false;
+    final length = actionIcons!.length;
+    int index = 0;
+    if (length == 0) {
+      return <Widget>[const SizedBox.shrink()];
+    }
+    if (length == 1) {
+      return actionIcons;
+    }
+    while (index < length) {
+      if (!addWhiteSpace) {
+        actions.add(actionIcons![index]);
+        index++;
+        addWhiteSpace = true;
+      } else {
+        actions.add(const SizedBox(width: 4));
+        addWhiteSpace = false;
+      }
+    }
+    return actions;
+  }
 }