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

Start to build join group pane

This commit is contained in:
Pierre HUBERT 2021-04-23 18:46:35 +02:00
parent 1fa4ed59d4
commit 0cd6ed284b
7 changed files with 123 additions and 24 deletions

View File

@ -1,21 +0,0 @@
import 'package:comunic/ui/routes/tour_route.dart';
import 'package:comunic/ui/widgets/tour/first_pane.dart';
import 'package:comunic/ui/widgets/tour/last_pane.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Forez tour builder
///
/// Handles the presentation tour for the Forez flavor application
///
/// @author Pierre Hubert
List<Widget> buildTour(TourRouteState state) => [
FirstTourPane(
msgOne: tr(
"Welcome to #Forez, the central application dedicated to events planning in the Forez plain!"),
msgTwo: tr(
"Let's configure the application and present you some features!"),
),
LastTourPane(),
];

View File

@ -1,6 +1,6 @@
import 'dart:io';
import 'package:comunic/forez/forez_tour_builder.dart';
import 'package:comunic/forez/tour/forez_tour_builder.dart';
import 'package:comunic/main.dart';
import 'package:comunic/models/config.dart';
import 'package:comunic/utils/intl_utils.dart';

View File

@ -0,0 +1,33 @@
import 'package:comunic/forez/tour/join_group_pane.dart';
import 'package:comunic/ui/routes/tour_route.dart';
import 'package:comunic/ui/widgets/tour/first_pane.dart';
import 'package:comunic/ui/widgets/tour/last_pane.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Forez tour builder
///
/// Handles the presentation tour for the Forez flavor application
///
/// @author Pierre Hubert
const _JOIN_GROUP_KEY_ID = 1;
List<Widget> buildTour(TourRouteState state) {
if (!state.pubKeys.containsKey(_JOIN_GROUP_KEY_ID))
state.pubKeys[_JOIN_GROUP_KEY_ID] = GlobalKey();
return [
FirstTourPane(
msgOne: tr(
"Welcome to #Forez, the central application dedicated to events planning in the Forez plain!"),
msgTwo: tr(
"Let's configure the application and present you some essential features!"),
),
JoinGroupPane(
key: state.pubKeys[_JOIN_GROUP_KEY_ID],
onUpdated: () => state.rebuild(),
),
LastTourPane(),
];
}

View File

@ -0,0 +1,66 @@
import 'package:comunic/helpers/forez_groups_helper.dart';
import 'package:comunic/models/group.dart';
import 'package:comunic/ui/widgets/async_screen_widget.dart';
import 'package:comunic/ui/widgets/tour/presentation_pane.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Ask the user to join a Forez group
///
/// @author Pierre Hubert
class JoinGroupPane extends PresentationPane {
JoinGroupPane({
@required Function() onUpdated,
@required GlobalKey key,
}) : super(
icon: Icons.login,
title: tr("Join a group"),
child: (c) => _JoinGroupPaneBody(
key: key,
onUpdated: onUpdated,
),
);
}
class _JoinGroupPaneBody extends StatefulWidget {
final Function() onUpdated;
const _JoinGroupPaneBody({
Key key,
@required this.onUpdated,
}) : assert(onUpdated != null),
super(key: key);
@override
__JoinGroupPaneBodyState createState() => __JoinGroupPaneBodyState();
}
class __JoinGroupPaneBodyState extends State<_JoinGroupPaneBody> {
List<Group> _groups;
Future<void> _load() async {
_groups = await ForezGroupsHelper.getForezGroups();
}
@override
Widget build(BuildContext context) => AsyncScreenWidget(
onReload: _load,
onBuild: onBuild,
errorMessage: tr("Failed to load the list of Forez groups!"));
List<Widget> get _initialWidgets => [
Text(tr("Please choose now the Forez group you want to join...")),
];
Widget onBuild() => Flexible(
child: ListView.builder(
itemCount: _initialWidgets.length + _groups.length,
itemBuilder: (c, i) {
if (i < _initialWidgets.length) return _initialWidgets[i];
final group = _groups[i - _initialWidgets.length];
return ListTile();
},
));
}

View File

@ -0,0 +1,17 @@
import 'package:comunic/helpers/groups_helper.dart';
import 'package:comunic/models/api_request.dart';
import 'package:comunic/models/group.dart';
/// Forez groups helper
///
/// @author Pierre Hubert
class ForezGroupsHelper {
static Future<List<Group>> getForezGroups() async {
return (await APIRequest.withLogin("forez/get_groups").execWithThrow())
.getArray()
.cast<Map<String, dynamic>>()
.map(GroupsHelper.getGroupFromAPI)
.toList();
}
}

View File

@ -70,7 +70,7 @@ class GroupsHelper {
response
.getObject()
.forEach((k, d) => list[int.parse(k)] = _getGroupFromAPI(d));
.forEach((k, d) => list[int.parse(k)] = getGroupFromAPI(d));
return list;
}
@ -370,7 +370,7 @@ class GroupsHelper {
.execWithThrow();
/// Turn an API entry into a group object
Group _getGroupFromAPI(Map<String, dynamic> map) {
static Group getGroupFromAPI(Map<String, dynamic> map) {
return Group(
id: map["id"],
name: map["name"],

View File

@ -35,6 +35,8 @@ class TourRouteState extends State<TourRoute> {
final pushNotificationsKey =
GlobalKey<PushNotificationsConfigurationWidgetState>();
final Map<int, GlobalKey> pubKeys = Map();
User currUser;
int _defaultIndex = 0;
@ -44,6 +46,8 @@ class TourRouteState extends State<TourRoute> {
await UsersHelper().getSingleWithThrow(userID(), forceDownload: true);
}
void rebuild() => setState(() {});
void setStateKeepCurrentIndex(BuildContext cxt) async {
_defaultIndex = DefaultTabController.of(cxt).index;
await _key.currentState.refresh();