mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Add support for banner timeout
This commit is contained in:
parent
90b3ffbe81
commit
71a72d4f04
@ -1,5 +1,8 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:comunic/helpers/server_config_helper.dart';
|
import 'package:comunic/helpers/server_config_helper.dart';
|
||||||
import 'package:comunic/models/server_config.dart';
|
import 'package:comunic/models/server_config.dart';
|
||||||
|
import 'package:comunic/utils/date_utils.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
@ -14,17 +17,37 @@ class BannerWidget extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _BannerWidgetState extends State<BannerWidget> {
|
class _BannerWidgetState extends State<BannerWidget> {
|
||||||
|
Timer _timer;
|
||||||
|
|
||||||
|
bool get _shouldShowBanner => showBanner && !_bannerDismissed;
|
||||||
|
|
||||||
void _hideBanner() {
|
void _hideBanner() {
|
||||||
setState(() => _bannerDismissed = true);
|
if (this.mounted) setState(() => _bannerDismissed = true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _openLink() {
|
void _openLink() {
|
||||||
launch(srvConfig.banner.link);
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (!showBanner || _bannerDismissed) return Container();
|
if (!_shouldShowBanner) return Container();
|
||||||
|
|
||||||
final banner = srvConfig.banner;
|
final banner = srvConfig.banner;
|
||||||
return Card(
|
return Card(
|
||||||
|
Loading…
Reference in New Issue
Block a user