|
1 | 1 | import 'dart:async'; |
2 | 2 | import 'dart:io'; |
3 | 3 |
|
| 4 | +import 'package:auto_updater/auto_updater.dart'; |
4 | 5 | import 'package:dipantau_desktop_client/core/network/network_info.dart'; |
5 | 6 | import 'package:dipantau_desktop_client/core/util/enum/global_variable.dart'; |
6 | 7 | import 'package:dipantau_desktop_client/core/util/helper.dart'; |
@@ -76,6 +77,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener { |
76 | 77 | final listTrackLocal = <Track>[]; |
77 | 78 | final listPathStartScreenshots = <String?>[]; |
78 | 79 | final networkInfo = sl<NetworkInfo>(); |
| 80 | + final valueNotifierShowBannerUpdate = ValueNotifier(false); |
79 | 81 |
|
80 | 82 | var isWindowVisible = true; |
81 | 83 | var userId = ''; |
@@ -130,6 +132,8 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener { |
130 | 132 | } |
131 | 133 | setupCronTimer(); |
132 | 134 | doLoadDataTask(); |
| 135 | + final isNewUpdateAvailable = await widgetHelper.isNewUpdateAvailable(); |
| 136 | + valueNotifierShowBannerUpdate.value = isNewUpdateAvailable; |
133 | 137 | }); |
134 | 138 | super.initState(); |
135 | 139 | } |
@@ -506,7 +510,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener { |
506 | 510 | ), |
507 | 511 | ), |
508 | 512 | floatingActionButton: FloatingActionButton( |
509 | | - onPressed: () { |
| 513 | + onPressed: () async { |
510 | 514 | context.pushNamed(ManualTrackingPage.routeName).then((value) { |
511 | 515 | // TODO: refresh data home jika add manual tracking-nya pada hari ini dan di project yang sama |
512 | 516 | }); |
@@ -555,6 +559,7 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener { |
555 | 559 | child: Column( |
556 | 560 | crossAxisAlignment: CrossAxisAlignment.center, |
557 | 561 | children: [ |
| 562 | + buildWidgetBannerUpdate(), |
558 | 563 | buildWidgetFieldProject(), |
559 | 564 | const SizedBox(height: 24), |
560 | 565 | buildWidgetTimer(), |
@@ -1487,4 +1492,68 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener { |
1487 | 1492 | ); |
1488 | 1493 | } |
1489 | 1494 | } |
| 1495 | + |
| 1496 | + Widget buildWidgetBannerUpdate() { |
| 1497 | + return ValueListenableBuilder( |
| 1498 | + valueListenable: valueNotifierShowBannerUpdate, |
| 1499 | + builder: (BuildContext context, bool isShow, _) { |
| 1500 | + if (!isShow) { |
| 1501 | + return Container(); |
| 1502 | + } |
| 1503 | + return Column( |
| 1504 | + children: [ |
| 1505 | + Material( |
| 1506 | + borderRadius: BorderRadius.circular(8), |
| 1507 | + color: Theme.of(context).colorScheme.primaryContainer, |
| 1508 | + child: InkWell( |
| 1509 | + borderRadius: BorderRadius.circular(8), |
| 1510 | + onTap: () { |
| 1511 | + const feedURL = autoUpdaterUrl; |
| 1512 | + autoUpdater.setFeedURL(feedURL); |
| 1513 | + autoUpdater.checkForUpdates(); |
| 1514 | + valueNotifierShowBannerUpdate.value = false; |
| 1515 | + }, |
| 1516 | + child: Container( |
| 1517 | + width: double.infinity, |
| 1518 | + padding: const EdgeInsets.all(8), |
| 1519 | + decoration: BoxDecoration( |
| 1520 | + borderRadius: BorderRadius.circular(8), |
| 1521 | + ), |
| 1522 | + child: Row( |
| 1523 | + children: [ |
| 1524 | + Expanded( |
| 1525 | + child: Padding( |
| 1526 | + padding: const EdgeInsets.only(left: 8.0), |
| 1527 | + child: Column( |
| 1528 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 1529 | + children: [ |
| 1530 | + Text( |
| 1531 | + 'title_new_update_available'.tr(), |
| 1532 | + style: Theme.of(context).textTheme.bodyLarge, |
| 1533 | + ), |
| 1534 | + Text( |
| 1535 | + 'description_new_update_available'.tr(), |
| 1536 | + style: Theme.of(context).textTheme.bodySmall, |
| 1537 | + ), |
| 1538 | + ], |
| 1539 | + ), |
| 1540 | + ), |
| 1541 | + ), |
| 1542 | + IconButton( |
| 1543 | + onPressed: () { |
| 1544 | + valueNotifierShowBannerUpdate.value = false; |
| 1545 | + }, |
| 1546 | + icon: const Icon(Icons.clear), |
| 1547 | + ), |
| 1548 | + ], |
| 1549 | + ), |
| 1550 | + ), |
| 1551 | + ), |
| 1552 | + ), |
| 1553 | + const SizedBox(height: 16), |
| 1554 | + ], |
| 1555 | + ); |
| 1556 | + }, |
| 1557 | + ); |
| 1558 | + } |
1490 | 1559 | } |
0 commit comments