1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +00:00

Add support for banner timeout

This commit is contained in:
Pierre HUBERT 2021-12-30 12:22:10 +01:00
parent 90b3ffbe81
commit 71a72d4f04

View File

@ -1,5 +1,8 @@
import 'dart:async';
import 'package:comunic/helpers/server_config_helper.dart';
import 'package:comunic/models/server_config.dart';
import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
@ -14,17 +17,37 @@ class BannerWidget extends StatefulWidget {
}
class _BannerWidgetState extends State<BannerWidget> {
Timer _timer;
bool get _shouldShowBanner => showBanner && !_bannerDismissed;
void _hideBanner() {
setState(() => _bannerDismissed = true);
if (this.mounted) setState(() => _bannerDismissed = true);
}
void _openLink() {
launch(srvConfig.banner.link);
}
@override
void initState() {
super.initState();
if (_shouldShowBanner && srvConfig.banner.expire != null) {
_timer = Timer(
Duration(seconds: srvConfig.banner.expire - time()), _hideBanner);
}
}
@override
void dispose() {
if (_timer != null) _timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (!showBanner || _bannerDismissed) return Container();
if (!_shouldShowBanner) return Container();
final banner = srvConfig.banner;
return Card(