develop-polls #93
@@ -7,54 +7,56 @@ part of 'getPollStateResponse.dart';
|
|||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
GetPollStateResponse _$GetPollStateResponseFromJson(
|
GetPollStateResponse _$GetPollStateResponseFromJson(
|
||||||
Map<String, dynamic> json) =>
|
Map<String, dynamic> json,
|
||||||
|
) =>
|
||||||
GetPollStateResponse(
|
GetPollStateResponse(
|
||||||
GetPollStateResponseObject.fromJson(json['data'] as Map<String, dynamic>),
|
GetPollStateResponseObject.fromJson(
|
||||||
)..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
json['data'] as Map<String, dynamic>,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||||
(k, e) => MapEntry(k, e as String),
|
(k, e) => MapEntry(k, e as String),
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$GetPollStateResponseToJson(
|
Map<String, dynamic> _$GetPollStateResponseToJson(
|
||||||
GetPollStateResponse instance) =>
|
GetPollStateResponse instance,
|
||||||
<String, dynamic>{
|
) => <String, dynamic>{
|
||||||
if (instance.headers case final value?) 'headers': value,
|
'headers': ?instance.headers,
|
||||||
'data': instance.data.toJson(),
|
'data': instance.data.toJson(),
|
||||||
};
|
};
|
||||||
|
|
||||||
GetPollStateResponseObject _$GetPollStateResponseObjectFromJson(
|
GetPollStateResponseObject _$GetPollStateResponseObjectFromJson(
|
||||||
Map<String, dynamic> json) =>
|
Map<String, dynamic> json,
|
||||||
GetPollStateResponseObject(
|
) => GetPollStateResponseObject(
|
||||||
(json['id'] as num).toInt(),
|
(json['id'] as num).toInt(),
|
||||||
json['question'] as String,
|
json['question'] as String,
|
||||||
(json['options'] as List<dynamic>).map((e) => e as String).toList(),
|
(json['options'] as List<dynamic>).map((e) => e as String).toList(),
|
||||||
json['votes'],
|
json['votes'],
|
||||||
json['actorType'] as String,
|
json['actorType'] as String,
|
||||||
json['actorId'] as String,
|
json['actorId'] as String,
|
||||||
json['actorDisplayName'] as String,
|
json['actorDisplayName'] as String,
|
||||||
(json['status'] as num).toInt(),
|
(json['status'] as num).toInt(),
|
||||||
(json['resultMode'] as num).toInt(),
|
(json['resultMode'] as num).toInt(),
|
||||||
(json['maxVotes'] as num).toInt(),
|
(json['maxVotes'] as num).toInt(),
|
||||||
(json['votedSelf'] as List<dynamic>)
|
(json['votedSelf'] as List<dynamic>).map((e) => (e as num).toInt()).toList(),
|
||||||
.map((e) => (e as num).toInt())
|
(json['numVoters'] as num?)?.toInt(),
|
||||||
.toList(),
|
(json['details'] as List<dynamic>?)?.map((e) => e as String).toList(),
|
||||||
(json['numVoters'] as num?)?.toInt(),
|
);
|
||||||
(json['details'] as List<dynamic>?)?.map((e) => e as String).toList(),
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, dynamic> _$GetPollStateResponseObjectToJson(
|
Map<String, dynamic> _$GetPollStateResponseObjectToJson(
|
||||||
GetPollStateResponseObject instance) =>
|
GetPollStateResponseObject instance,
|
||||||
<String, dynamic>{
|
) => <String, dynamic>{
|
||||||
'id': instance.id,
|
'id': instance.id,
|
||||||
'question': instance.question,
|
'question': instance.question,
|
||||||
'options': instance.options,
|
'options': instance.options,
|
||||||
'votes': instance.votes,
|
'votes': instance.votes,
|
||||||
'actorType': instance.actorType,
|
'actorType': instance.actorType,
|
||||||
'actorId': instance.actorId,
|
'actorId': instance.actorId,
|
||||||
'actorDisplayName': instance.actorDisplayName,
|
'actorDisplayName': instance.actorDisplayName,
|
||||||
'status': instance.status,
|
'status': instance.status,
|
||||||
'resultMode': instance.resultMode,
|
'resultMode': instance.resultMode,
|
||||||
'maxVotes': instance.maxVotes,
|
'maxVotes': instance.maxVotes,
|
||||||
'votedSelf': instance.votedSelf,
|
'votedSelf': instance.votedSelf,
|
||||||
'numVoters': instance.numVoters,
|
'numVoters': instance.numVoters,
|
||||||
'details': instance.details,
|
'details': instance.details,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import '../getPoll/getPollStateResponse.dart';
|
|||||||
import '../talkApi.dart';
|
import '../talkApi.dart';
|
||||||
import 'votePollParams.dart';
|
import 'votePollParams.dart';
|
||||||
|
|
||||||
|
@Deprecated('VotePoll is broken (known issues)')
|
||||||
class VotePoll extends TalkApi {
|
class VotePoll extends TalkApi {
|
||||||
String token;
|
String token;
|
||||||
int pollId;
|
int pollId;
|
||||||
|
|||||||
@@ -14,6 +14,4 @@ VotePollParams _$VotePollParamsFromJson(Map<String, dynamic> json) =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$VotePollParamsToJson(VotePollParams instance) =>
|
Map<String, dynamic> _$VotePollParamsToJson(VotePollParams instance) =>
|
||||||
<String, dynamic>{
|
<String, dynamic>{'optionIds': instance.optionIds};
|
||||||
'optionIds': instance.optionIds,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import 'package:flutter/services.dart';
|
|||||||
import 'package:jiffy/jiffy.dart';
|
import 'package:jiffy/jiffy.dart';
|
||||||
import 'package:open_filex/open_filex.dart';
|
import 'package:open_filex/open_filex.dart';
|
||||||
import '../../../../api/marianumcloud/talk/getPoll/getPollState.dart';
|
import '../../../../api/marianumcloud/talk/getPoll/getPollState.dart';
|
||||||
import '../../../../api/marianumcloud/talk/votePoll/votePoll.dart';
|
|
||||||
import '../../../../api/marianumcloud/talk/votePoll/votePollParams.dart';
|
|
||||||
import '../../../../extensions/text.dart';
|
import '../../../../extensions/text.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -305,7 +303,6 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
|
|||||||
if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
|
if(message.originalData?['object']?.type == RichObjectStringObjectType.talkPoll) {
|
||||||
var pollId = int.parse(message.originalData!['object']!.id);
|
var pollId = int.parse(message.originalData!['object']!.id);
|
||||||
var pollState = GetPollState(token: widget.bubbleData.token, pollId: pollId).run();
|
var pollState = GetPollState(token: widget.bubbleData.token, pollId: pollId).run();
|
||||||
List<int>? ownVotes;
|
|
||||||
showDialog(context: context, builder: (context) => AlertDialog(
|
showDialog(context: context, builder: (context) => AlertDialog(
|
||||||
title: Text(message.originalData!['object']!.name, textScaler: TextScaler.linear(0.9)),
|
title: Text(message.originalData!['object']!.name, textScaler: TextScaler.linear(0.9)),
|
||||||
|
Pupsi marked this conversation as resolved
Outdated
|
|||||||
content: FutureBuilder(
|
content: FutureBuilder(
|
||||||
@@ -314,26 +311,20 @@ class _ChatBubbleState extends State<ChatBubble> with SingleTickerProviderStateM
|
|||||||
if(snapshot.connectionState == ConnectionState.waiting) return const Column(mainAxisSize: MainAxisSize.min, children: [LoadingSpinner()]);
|
if(snapshot.connectionState == ConnectionState.waiting) return const Column(mainAxisSize: MainAxisSize.min, children: [LoadingSpinner()]);
|
||||||
|
|
||||||
var pollData = snapshot.data!.data;
|
var pollData = snapshot.data!.data;
|
||||||
ownVotes = pollData.votedSelf;
|
return ListView(
|
||||||
return PollOptionsList(
|
shrinkWrap: true,
|
||||||
pollData: pollData,
|
children: [
|
||||||
callback: (votes) => ownVotes = votes
|
PollOptionsList(
|
||||||
|
pollData: pollData
|
||||||
|
)
|
||||||
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
FutureBuilder(future: pollState, builder: (context, snapshot) => TextButton(
|
|
||||||
onPressed: () async {
|
|
||||||
if(snapshot.connectionState != ConnectionState.done) return;
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
if(ownVotes == null) return;
|
|
||||||
VotePoll(pollId: pollId, token: widget.bubbleData.token, params: VotePollParams(optionIds: ownVotes!)).run();
|
|
||||||
},
|
|
||||||
child: const Text('Stimme abgeben')
|
|
||||||
)),
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: const Text('Abbrechen')
|
child: const Text('Zurück')
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -1,45 +1,69 @@
|
|||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_linkify/flutter_linkify.dart';
|
||||||
|
|
||||||
import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart';
|
import '../../../../api/marianumcloud/talk/getPoll/getPollStateResponse.dart';
|
||||||
|
|
||||||
class PollOptionsList extends StatefulWidget {
|
class PollOptionsList extends StatefulWidget {
|
||||||
final GetPollStateResponseObject pollData;
|
final GetPollStateResponseObject pollData;
|
||||||
final Function(List<int>) callback;
|
const PollOptionsList({super.key, required this.pollData});
|
||||||
const PollOptionsList({super.key, required this.pollData, required this.callback});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<PollOptionsList> createState() => _PollOptionsListState();
|
State<PollOptionsList> createState() => _PollOptionsListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PollOptionsListState extends State<PollOptionsList> {
|
class _PollOptionsListState extends State<PollOptionsList> {
|
||||||
late List<int> ownVotes;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
ownVotes = widget.pollData.votedSelf;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Column(
|
Widget build(BuildContext context) => Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
...widget.pollData.options.map<Widget>((option) => CheckboxListTile(
|
...widget.pollData.options.map<Widget>((option) {
|
||||||
value: ownVotes.contains(widget.pollData.options.indexOf(option)),
|
var optionId = widget.pollData.options.indexOf(option);
|
||||||
title: Text(option),
|
var votedSelf = widget.pollData.votedSelf.contains(optionId);
|
||||||
onChanged: (value) {
|
var votes = widget.pollData.votes.runtimeType is Map<String, dynamic>
|
||||||
var optionId = widget.pollData.options.indexOf(option);
|
? widget.pollData.votes['option-$optionId']
|
||||||
|
Pupsi marked this conversation as resolved
Outdated
MineTec
commented
format ist komisch format ist komisch
|
|||||||
setState(() {
|
: 0;
|
||||||
if(ownVotes.contains(optionId)) {
|
int numVoters = 1;
|
||||||
ownVotes.remove(optionId);
|
if(widget.pollData.numVoters != null && widget.pollData.numVoters != 0) {
|
||||||
} else {
|
numVoters = widget.pollData.numVoters!;
|
||||||
ownVotes.add(optionId);
|
}
|
||||||
}
|
var portion = (votes / numVoters);
|
||||||
});
|
return ListTile(
|
||||||
widget.callback(ownVotes);
|
enabled: false,
|
||||||
}
|
isThreeLine: true,
|
||||||
)
|
title: Text(
|
||||||
|
option,
|
||||||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
trailing: Icon(
|
||||||
|
votedSelf ? Icons.check_circle_outlined : Icons.circle_outlined,
|
||||||
|
color: votedSelf
|
||||||
|
? Theme.of(context).colorScheme.primary.withValues(alpha: 0.8)
|
||||||
|
: Theme.of(context).colorScheme.onSurfaceVariant.withValues(alpha: 0.8),
|
||||||
|
),
|
||||||
|
subtitle: Visibility(
|
||||||
|
visible: widget.pollData.numVoters != null,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: LinearProgressIndicator(value: portion),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.only(left: 10),
|
||||||
|
child: Text('${(portion * 100).round()}%'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
ListTile(
|
||||||
|
title: Linkify(
|
||||||
|
text: 'Zurzeit kann in dieser App leider nicht an Abstimmungen teilgenommen werden. '
|
||||||
|
'Um abzustimmen verwende die Webversion unter https://cloud.marianum-fulda.de',
|
||||||
|
style: Theme.of(context).textTheme.bodySmall,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user
ist der scale an andern stellen auch so präsent?