From 1de7e699d7c70e685e1f27e57ee0e252636c0d28 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 24 Apr 2021 09:16:29 +0200 Subject: [PATCH] Start to build Forez main route --- lib/forez/main_forez_dev.dart | 2 + lib/forez/ui/routes/forez_route.dart | 65 ++++++++++++++++++++++++++++ lib/models/config.dart | 7 +++ lib/ui/widgets/init_widget.dart | 13 +++--- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 lib/forez/ui/routes/forez_route.dart diff --git a/lib/forez/main_forez_dev.dart b/lib/forez/main_forez_dev.dart index 06abfd4..f277c81 100644 --- a/lib/forez/main_forez_dev.dart +++ b/lib/forez/main_forez_dev.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:comunic/forez/tour/forez_tour_builder.dart'; +import 'package:comunic/forez/ui/routes/forez_route.dart'; import 'package:comunic/main.dart'; import 'package:comunic/models/config.dart'; import 'package:comunic/utils/intl_utils.dart'; @@ -33,6 +34,7 @@ void main() { appName: "#Forez", appQuickDescription: tr("Events organisation in Forez plain"), toursEntriesBuilder: buildTour, + mainRouteBuilder: (c) => ForezRoute(), )); HttpOverrides.global = new MyHttpOverride(); diff --git a/lib/forez/ui/routes/forez_route.dart b/lib/forez/ui/routes/forez_route.dart new file mode 100644 index 0000000..7ca8df0 --- /dev/null +++ b/lib/forez/ui/routes/forez_route.dart @@ -0,0 +1,65 @@ +import 'package:comunic/models/conversation.dart'; +import 'package:comunic/ui/dialogs/alert_dialog.dart'; +import 'package:comunic/ui/routes/main_route/main_route.dart'; +import 'package:comunic/ui/routes/main_route/page_info.dart'; +import 'package:comunic/utils/intl_utils.dart'; +import 'package:flutter/material.dart'; + +/// Forez route +/// +/// @author Pierre Hubert + +class ForezRoute extends StatefulWidget implements MainRoute { + const ForezRoute({Key key}) : super(key: key); + + @override + State createState() => _MainRouteState(); +} + +/// Private implementation of HomeController +class _MainRouteState extends MainController { + @override + PageInfo get defaultPage => PageInfo( + type: PageType.OTHER_PAGE, child: ForezRouteBody(), hideNavBar: true); + + @override + Widget build(BuildContext context) { + return Container( + color: Colors.blueAccent, + child: SafeArea( + // Avoid OS areas + child: WillPopScope( + onWillPop: willPop, + child: Scaffold( + appBar: currentPage.hideNavBar ? null : AppBar(), + body: SafeArea(key: currentPage.key, child: currentPage.child), + ), + ), + ), + ); + } + + @override + void openConversation(Conversation conv, {fullScreen: false}) { + // Forcefully open conversations in a "normal" way (do not display groups) + openConversationById(conv.id, fullScreen: fullScreen); + } + + @override + void openGroup(int groupID, {int conversationID}) { + alert(context, + tr("This feature is available only in the Comunic application!")); + } +} + +class ForezRouteBody extends StatefulWidget { + @override + _ForezRouteBodyState createState() => _ForezRouteBodyState(); +} + +class _ForezRouteBodyState extends State { + @override + Widget build(BuildContext context) { + return Text("yolo"); + } +} diff --git a/lib/models/config.dart b/lib/models/config.dart index b93e49e..32a8917 100644 --- a/lib/models/config.dart +++ b/lib/models/config.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:comunic/ui/routes/tour_route.dart'; +import 'package:flutter/material.dart'; import 'package:meta/meta.dart'; /// Application configuration model @@ -15,6 +16,8 @@ class Config { final String apiServerUri; final bool apiServerSecure; final String clientName; + + // Theme customization final Color splashBackgroundColor; final Color primaryColor; final Color primaryColorDark; @@ -24,6 +27,9 @@ class Config { // Entries for the welcome tour final TourEntriesBuilder toursEntriesBuilder; + // Custom main application route + final Widget Function(BuildContext) mainRouteBuilder; + const Config({ @required this.apiServerName, @required this.apiServerUri, @@ -35,6 +41,7 @@ class Config { this.appName = "Comunic", this.appQuickDescription, this.toursEntriesBuilder, + this.mainRouteBuilder, }) : assert(apiServerName != null), assert(apiServerUri != null), assert(apiServerSecure != null), diff --git a/lib/ui/widgets/init_widget.dart b/lib/ui/widgets/init_widget.dart index 1177658..bbcd5b0 100644 --- a/lib/ui/widgets/init_widget.dart +++ b/lib/ui/widgets/init_widget.dart @@ -105,11 +105,14 @@ class _InitializeWidgetState extends SafeState { @override Widget build(BuildContext context) { - return (!_error && WebSocketHelper.isConnected()) - ? (isTablet(context) - ? TabletRoute(key: mainControllerKey) - : SmartphoneMainRoute(key: mainControllerKey)) - : _buildNonReadyWidget(); + if (_error || !WebSocketHelper.isConnected()) return _buildNonReadyWidget(); + + if (config().mainRouteBuilder != null) + return config().mainRouteBuilder(context); + + return isTablet(context) + ? TabletRoute(key: mainControllerKey) + : SmartphoneMainRoute(key: mainControllerKey); } /// Build loading widget