Skip to content

Commit 31fd227

Browse files
committed
feat:Add download badge to navigation icon showing active task count
1 parent de93b15 commit 31fd227

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

lib/main.dart

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class MyHomePage extends StatelessWidget {
105105
label: S.current.appName,
106106
),
107107
NavigationDestination(
108-
icon: const Icon(Icons.arrow_downward),
108+
icon: _buildDownloadIcon(),
109109
label: '下载管理',
110110
),
111111
NavigationDestination(
@@ -124,6 +124,46 @@ class MyHomePage extends StatelessWidget {
124124
controller.setPageIndex(index);
125125
})));
126126
}
127+
128+
Widget _buildDownloadIcon() {
129+
return Obx(() {
130+
int activeCount = DownloadManager.activeTasks.length;
131+
132+
// 基础图标 - 使用可用的图标
133+
Widget baseIcon = const Icon(Icons.get_app); // 尝试 get_app 图标
134+
135+
if (activeCount > 0) {
136+
// 有活跃下载时,显示简单的文字徽章
137+
return Stack(
138+
clipBehavior: Clip.none,
139+
children: [
140+
baseIcon,
141+
Positioned(
142+
right: -8,
143+
top: -8,
144+
child: Container(
145+
padding: const EdgeInsets.all(4),
146+
decoration: const BoxDecoration(
147+
color: Colors.red,
148+
shape: BoxShape.circle,
149+
),
150+
child: Text(
151+
'$activeCount',
152+
style: const TextStyle(
153+
color: Colors.white,
154+
fontSize: 10,
155+
fontWeight: FontWeight.bold,
156+
),
157+
),
158+
),
159+
),
160+
],
161+
);
162+
} else {
163+
return baseIcon;
164+
}
165+
});
166+
}
127167
}
128168

129169
class _MainController extends GetxController {

0 commit comments

Comments
 (0)