Skip to content

Commit 7bf56db

Browse files
committed
refactor: extract download icon widget to separate method and update icon design
1 parent 9a08c6c commit 7bf56db

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:width="24dp"
4-
android:height="24dp"
5-
android:viewportWidth="24"
6-
android:viewportHeight="24">
7-
<path
8-
android:fillColor="#FF000000"
9-
android:pathData="M19,9h-4V3H9v6H5l7,7 7,-7zM5,18v2h14v-2H5z"/>
10-
</vector>
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="1024" android:viewportWidth="1024" android:width="24dp">
2+
3+
<path android:fillColor="#000000" android:pathData="M853.3,853.3a42.7,42.7 0,0 1,0 85.3H170.7a42.7,42.7 0,0 1,0 -85.3h682.7zM512,85.5a42.7,42.7 0,0 1,42.7 42.7v515.4l204.4,-204.4a42.7,42.7 0,0 1,63.9 56.3l-3.6,4 -277.4,277.5a42.7,42.7 0,0 1,-56.3 3.6l-4,-3.5 -277.1,-276.7a42.7,42.7 0,0 1,56.2 -64l4,3.5L469.3,644.1V128.2a42.7,42.7 0,0 1,42.7 -42.7z"/>
4+
5+
</vector>

lib/main.dart

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -114,38 +114,7 @@ class MyHomePage extends StatelessWidget {
114114
label: S.current.appName,
115115
),
116116
NavigationDestination(
117-
icon: Obx(() {
118-
int activeCount = DownloadManager.activeTasks.length;
119-
return Stack(
120-
children: [
121-
const Icon(Icons.download),
122-
if (activeCount > 0)
123-
Positioned(
124-
right: 0,
125-
top: 0,
126-
child: Container(
127-
padding: const EdgeInsets.all(2),
128-
decoration: BoxDecoration(
129-
color: Colors.red,
130-
borderRadius: BorderRadius.circular(10),
131-
),
132-
constraints: const BoxConstraints(
133-
minWidth: 16,
134-
minHeight: 16,
135-
),
136-
child: Text(
137-
'$activeCount',
138-
style: const TextStyle(
139-
color: Colors.white,
140-
fontSize: 10,
141-
),
142-
textAlign: TextAlign.center,
143-
),
144-
),
145-
),
146-
],
147-
);
148-
}),
117+
icon: _buildDownloadIcon(),
149118
label: '下载管理',
150119
),
151120
NavigationDestination(
@@ -164,6 +133,41 @@ class MyHomePage extends StatelessWidget {
164133
controller.setPageIndex(index);
165134
})));
166135
}
136+
137+
Widget _buildDownloadIcon() {
138+
return Obx(() {
139+
int activeCount = DownloadManager.activeTasks.length;
140+
return Stack(
141+
children: [
142+
const Icon(Icons.download),
143+
if (activeCount > 0)
144+
Positioned(
145+
right: 0,
146+
top: 0,
147+
child: Container(
148+
padding: const EdgeInsets.all(2),
149+
decoration: BoxDecoration(
150+
color: Colors.red,
151+
borderRadius: BorderRadius.circular(10),
152+
),
153+
constraints: const BoxConstraints(
154+
minWidth: 16,
155+
minHeight: 16,
156+
),
157+
child: Text(
158+
'$activeCount',
159+
style: const TextStyle(
160+
color: Colors.white,
161+
fontSize: 10,
162+
),
163+
textAlign: TextAlign.center,
164+
),
165+
),
166+
),
167+
],
168+
);
169+
});
170+
}
167171
}
168172

169173
class _MainController extends GetxController {

0 commit comments

Comments
 (0)