[fix]: Use FutureBuilder for updatable apps count
This commit is contained in:
+59
-46
@@ -1,4 +1,5 @@
|
|||||||
import 'package:florid/l10n/app_localizations.dart';
|
import 'package:florid/l10n/app_localizations.dart';
|
||||||
|
import 'package:florid/models/fdroid_app.dart';
|
||||||
import 'package:florid/screens/library_screen.dart';
|
import 'package:florid/screens/library_screen.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:material_symbols_icons/symbols.dart';
|
import 'package:material_symbols_icons/symbols.dart';
|
||||||
@@ -51,54 +52,66 @@ class _FloridAppState extends State<FloridApp> {
|
|||||||
body: IndexedStack(index: _currentIndex, children: _screens),
|
body: IndexedStack(index: _currentIndex, children: _screens),
|
||||||
bottomNavigationBar: Consumer<AppProvider>(
|
bottomNavigationBar: Consumer<AppProvider>(
|
||||||
builder: (context, appProvider, child) {
|
builder: (context, appProvider, child) {
|
||||||
final updatableAppsCount = appProvider.getUpdatableApps().length;
|
return FutureBuilder<List<FDroidApp>>(
|
||||||
|
future: appProvider.getUpdatableApps(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final updatableAppsCount = snapshot.data?.length ?? 0;
|
||||||
|
// Build destinations with translations
|
||||||
|
final destinations = [
|
||||||
|
NavigationDestination(
|
||||||
|
icon: const Icon(Symbols.newsstand_rounded),
|
||||||
|
selectedIcon: const Icon(
|
||||||
|
Symbols.newsstand_rounded,
|
||||||
|
fill: 1,
|
||||||
|
weight: 600,
|
||||||
|
),
|
||||||
|
label: AppLocalizations.of(context)!.home,
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: const Icon(Symbols.search),
|
||||||
|
selectedIcon: const Icon(
|
||||||
|
Symbols.search,
|
||||||
|
fill: 1,
|
||||||
|
weight: 600,
|
||||||
|
),
|
||||||
|
label: AppLocalizations.of(context)!.search,
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: updatableAppsCount > 0
|
||||||
|
? Badge.count(
|
||||||
|
count: updatableAppsCount,
|
||||||
|
child: const Icon(Symbols.mobile_3_rounded),
|
||||||
|
)
|
||||||
|
: const Icon(Symbols.mobile_3_rounded),
|
||||||
|
selectedIcon: updatableAppsCount > 0
|
||||||
|
? Badge.count(
|
||||||
|
count: updatableAppsCount,
|
||||||
|
child: const Icon(
|
||||||
|
Symbols.mobile_3_rounded,
|
||||||
|
fill: 1,
|
||||||
|
weight: 600,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: const Icon(
|
||||||
|
Symbols.mobile_3_rounded,
|
||||||
|
fill: 1,
|
||||||
|
weight: 600,
|
||||||
|
),
|
||||||
|
label: AppLocalizations.of(context)!.device,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
// Build destinations with translations
|
return NavigationBar(
|
||||||
final destinations = [
|
selectedIndex: _currentIndex,
|
||||||
NavigationDestination(
|
onDestinationSelected: (index) {
|
||||||
icon: const Icon(Symbols.newsstand_rounded),
|
setState(() {
|
||||||
selectedIcon: const Icon(
|
_currentIndex = index;
|
||||||
Symbols.newsstand_rounded,
|
});
|
||||||
fill: 1,
|
_tabNotifier.value = index;
|
||||||
weight: 600,
|
},
|
||||||
),
|
destinations: destinations,
|
||||||
label: AppLocalizations.of(context)!.home,
|
);
|
||||||
),
|
|
||||||
NavigationDestination(
|
|
||||||
icon: const Icon(Symbols.search),
|
|
||||||
selectedIcon: const Icon(Symbols.search, fill: 1, weight: 600),
|
|
||||||
label: AppLocalizations.of(context)!.search,
|
|
||||||
),
|
|
||||||
NavigationDestination(
|
|
||||||
icon: updatableAppsCount > 0
|
|
||||||
? Badge.count(
|
|
||||||
count: updatableAppsCount,
|
|
||||||
child: const Icon(Symbols.mobile_3_rounded),
|
|
||||||
)
|
|
||||||
: const Icon(Symbols.mobile_3_rounded),
|
|
||||||
selectedIcon: updatableAppsCount > 0
|
|
||||||
? Badge.count(
|
|
||||||
count: updatableAppsCount,
|
|
||||||
child: const Icon(
|
|
||||||
Symbols.mobile_3_rounded,
|
|
||||||
fill: 1,
|
|
||||||
weight: 600,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: const Icon(Symbols.mobile_3_rounded, fill: 1, weight: 600),
|
|
||||||
label: AppLocalizations.of(context)!.device,
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
return NavigationBar(
|
|
||||||
selectedIndex: _currentIndex,
|
|
||||||
onDestinationSelected: (index) {
|
|
||||||
setState(() {
|
|
||||||
_currentIndex = index;
|
|
||||||
});
|
|
||||||
_tabNotifier.value = index;
|
|
||||||
},
|
},
|
||||||
destinations: destinations,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user