mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-04 12:14:11 +00:00 
			
		
		
		
	Start to display banner
This commit is contained in:
		@@ -1,6 +1,7 @@
 | 
			
		||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
 | 
			
		||||
import 'package:comunic/ui/routes/main_route/page_info.dart';
 | 
			
		||||
import 'package:comunic/ui/screens/notifications_screen.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/banner_widget.dart';
 | 
			
		||||
import 'package:comunic/ui/widgets/mobile_mode/mobile_appbar_widget.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
@@ -33,7 +34,14 @@ class _MainRouteState extends MainController {
 | 
			
		||||
            appBar: currentPage.hideNavBar
 | 
			
		||||
                ? null
 | 
			
		||||
                : ComunicMobileAppBar(currentPage: currentPage),
 | 
			
		||||
            body: SafeArea(key: currentPage.key, child: currentPage.child),
 | 
			
		||||
            body: SafeArea(
 | 
			
		||||
                key: currentPage.key,
 | 
			
		||||
                child: Column(
 | 
			
		||||
                  children: [
 | 
			
		||||
                    BannerWidget(),
 | 
			
		||||
                    Expanded(child: currentPage.child)
 | 
			
		||||
                  ],
 | 
			
		||||
                )),
 | 
			
		||||
          ),
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										89
									
								
								lib/ui/widgets/banner_widget.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								lib/ui/widgets/banner_widget.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
			
		||||
import 'package:comunic/helpers/server_config_helper.dart';
 | 
			
		||||
import 'package:comunic/models/server_config.dart';
 | 
			
		||||
import 'package:comunic/utils/intl_utils.dart';
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
import 'package:url_launcher/url_launcher.dart';
 | 
			
		||||
 | 
			
		||||
bool _bannerDismissed = false;
 | 
			
		||||
 | 
			
		||||
class BannerWidget extends StatefulWidget {
 | 
			
		||||
  const BannerWidget({Key key}) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  _BannerWidgetState createState() => _BannerWidgetState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class _BannerWidgetState extends State<BannerWidget> {
 | 
			
		||||
  void _hideBanner() {
 | 
			
		||||
    setState(() => _bannerDismissed = true);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void _openLink() {
 | 
			
		||||
    launch(srvConfig.banner.link);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    if (!showBanner || _bannerDismissed) return Container();
 | 
			
		||||
 | 
			
		||||
    final banner = srvConfig.banner;
 | 
			
		||||
    return Card(
 | 
			
		||||
      color: banner.nature == BannerNature.Information
 | 
			
		||||
          ? Colors.blue
 | 
			
		||||
          : banner.nature == BannerNature.Success
 | 
			
		||||
              ? Colors.green
 | 
			
		||||
              : Colors.red,
 | 
			
		||||
      child: Padding(
 | 
			
		||||
        padding: const EdgeInsets.all(2.0),
 | 
			
		||||
        child: Row(
 | 
			
		||||
          children: [
 | 
			
		||||
            BannerButton(
 | 
			
		||||
              icon: Icon(
 | 
			
		||||
                banner.nature == BannerNature.Information
 | 
			
		||||
                    ? Icons.info
 | 
			
		||||
                    : banner.nature == BannerNature.Success
 | 
			
		||||
                        ? Icons.check
 | 
			
		||||
                        : Icons.warning,
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
            Flexible(
 | 
			
		||||
              child: Text(
 | 
			
		||||
                banner.message.containsKey(lang())
 | 
			
		||||
                    ? banner.message[lang()]
 | 
			
		||||
                    : banner.message["en"],
 | 
			
		||||
                style: TextStyle(color: Colors.white),
 | 
			
		||||
              ),
 | 
			
		||||
            ),
 | 
			
		||||
            banner.link == null
 | 
			
		||||
                ? Container()
 | 
			
		||||
                : BannerButton(
 | 
			
		||||
                    onPressed: _openLink,
 | 
			
		||||
                    icon: Icon(Icons.open_in_new),
 | 
			
		||||
                  ),
 | 
			
		||||
            BannerButton(
 | 
			
		||||
              onPressed: _hideBanner,
 | 
			
		||||
              icon: Icon(Icons.close),
 | 
			
		||||
            )
 | 
			
		||||
          ],
 | 
			
		||||
        ),
 | 
			
		||||
      ),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class BannerButton extends StatelessWidget {
 | 
			
		||||
  final Function() onPressed;
 | 
			
		||||
  final Widget icon;
 | 
			
		||||
 | 
			
		||||
  const BannerButton({this.onPressed, this.icon, Key key}) : super(key: key);
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  Widget build(BuildContext context) {
 | 
			
		||||
    return IconButton(
 | 
			
		||||
      onPressed: onPressed,
 | 
			
		||||
      icon: icon,
 | 
			
		||||
      disabledColor: Colors.white,
 | 
			
		||||
      padding: EdgeInsets.all(1.0),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user