implement info table popup

This commit is contained in:
krawieck 2020-10-26 18:47:49 +01:00
parent 53f19c5c57
commit e4055f073e
4 changed files with 49 additions and 202 deletions

View File

@ -3,7 +3,6 @@ import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:url_launcher/url_launcher.dart' as ul; import 'package:url_launcher/url_launcher.dart' as ul;
@ -18,6 +17,7 @@ import '../util/text_color.dart';
import '../widgets/badge.dart'; import '../widgets/badge.dart';
import '../widgets/bottom_modal.dart'; import '../widgets/bottom_modal.dart';
import '../widgets/fullscreenable_image.dart'; import '../widgets/fullscreenable_image.dart';
import '../widgets/info_table_popup.dart';
import '../widgets/markdown_text.dart'; import '../widgets/markdown_text.dart';
import '../widgets/sortable_infinite_list.dart'; import '../widgets/sortable_infinite_list.dart';
@ -131,33 +131,13 @@ class CommunityPage extends HookWidget {
leading: Icon(Icons.info_outline), leading: Icon(Icons.info_outline),
title: Text('Nerd stuff'), title: Text('Nerd stuff'),
onTap: () { onTap: () {
showDialog( showInfoTablePopup(context, {
context: context, 'id:': community.id,
child: SimpleDialog( 'actorId': community.actorId,
contentPadding: const EdgeInsets.symmetric( 'created by:': '@${community.creatorName}',
horizontal: 20, 'hot rank:': community.hotRank.toString(),
vertical: 15, 'published:': community.published.toString(),
), });
children: [
Table(
children: [
TableRow(children: [
Text('created by:'),
Text('@${community.creatorName}'),
]),
TableRow(children: [
Text('hot rank:'),
Text(community.hotRank.toString()),
]),
TableRow(children: [
Text('published:'),
Text(
'''${DateFormat.yMMMd().format(community.published)}'''
''' ${DateFormat.Hms().format(community.published)}'''),
]),
],
),
]));
}, },
), ),
], ],

View File

@ -3,17 +3,15 @@ import 'package:esys_flutter_share/esys_flutter_share.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:url_launcher/url_launcher.dart' as ul;
import '../hooks/stores.dart'; import '../hooks/stores.dart';
import '../util/extensions/api.dart'; import '../util/extensions/api.dart';
import '../util/goto.dart'; import '../util/goto.dart';
import '../util/text_color.dart'; import '../util/text_color.dart';
import '../widgets/badge.dart'; import '../widgets/badge.dart';
import '../widgets/bottom_modal.dart';
import '../widgets/fullscreenable_image.dart'; import '../widgets/fullscreenable_image.dart';
import '../widgets/info_table_popup.dart';
import '../widgets/markdown_text.dart'; import '../widgets/markdown_text.dart';
import '../widgets/sortable_infinite_list.dart'; import '../widgets/sortable_infinite_list.dart';
import 'communities_list.dart'; import 'communities_list.dart';
@ -70,73 +68,15 @@ class InstancePage extends HookWidget {
final site = siteSnap.data; final site = siteSnap.data;
void _openMoreMenu(BuildContext c) { void _openMoreMenu(BuildContext c) {
showModalBottomSheet( showInfoTablePopup(context, {
backgroundColor: Colors.transparent, 'url:': instanceUrl,
context: c, 'creator:': '@${site.site.creatorName}',
builder: (context) => BottomModal( 'version:': site.version,
child: Column( 'enableDownvotes:': site.site.enableDownvotes.toString(),
children: [ 'enableNsfw:': site.site.enableNsfw.toString(),
ListTile( 'published:': site.site.published,
leading: Icon(Icons.open_in_browser), 'updated:': site.site.updated,
title: Text('Open in browser'), });
onTap: () async => await ul.canLaunch('https://$instanceUrl')
? ul.launch('https://$instanceUrl')
: Scaffold.of(context).showSnackBar(
SnackBar(content: Text("can't open in browser"))),
),
ListTile(
leading: Icon(Icons.info_outline),
title: Text('Nerd stuff'),
onTap: () {
showDialog(
context: context,
child: SimpleDialog(
contentPadding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 15,
),
children: [
Table(
children: [
TableRow(children: [
Text('url:'),
Text(instanceUrl),
]),
TableRow(children: [
Text('creator:'),
Text('@${site.site.creatorName}')
]),
TableRow(children: [
Text('version:'),
Text(site.version),
]),
TableRow(children: [
Text('enableDownvotes:'),
Text(site.site.enableDownvotes.toString()),
]),
TableRow(children: [
Text('enableNsfw:'),
Text(site.site.enableNsfw.toString()),
]),
TableRow(children: [
Text('published:'),
Text(DateFormat.yMMMMd()
.format(site.site.published)),
]),
TableRow(children: [
Text('updated:'),
Text(DateFormat.yMMMMd()
.format(site.site.updated)),
]),
],
),
]));
},
),
],
),
),
);
} }
return Scaffold( return Scaffold(

View File

@ -4,7 +4,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:intl/intl.dart';
import 'package:lemmy_api_client/lemmy_api_client.dart'; import 'package:lemmy_api_client/lemmy_api_client.dart';
import 'package:timeago/timeago.dart' as timeago; import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart' as ul; import 'package:url_launcher/url_launcher.dart' as ul;
@ -17,6 +16,7 @@ import '../util/goto.dart';
import '../util/intl.dart'; import '../util/intl.dart';
import '../util/text_color.dart'; import '../util/text_color.dart';
import 'bottom_modal.dart'; import 'bottom_modal.dart';
import 'info_table_popup.dart';
import 'markdown_text.dart'; import 'markdown_text.dart';
import 'write_comment.dart'; import 'write_comment.dart';
@ -45,56 +45,20 @@ class Comment extends HookWidget {
_showCommentInfo(BuildContext context) { _showCommentInfo(BuildContext context) {
final com = commentTree.comment; final com = commentTree.comment;
showDialog( showInfoTablePopup(context, {
context: context, 'id': com.id.toString(),
child: SimpleDialog( 'apId': com.apId.toString(),
contentPadding: const EdgeInsets.symmetric( 'userId': com.userId.toString(),
horizontal: 20, 'upvotes:': com.upvotes.toString(),
vertical: 15, 'downvotes:': com.downvotes.toString(),
), 'score:': com.score.toString(),
children: [ '% of upvotes:':
Table( '${(100 * (com.upvotes / (com.upvotes + com.downvotes)))}%',
children: [ 'hotRank:': com.hotRank.toString(),
TableRow(children: [ 'hotRankActive:': com.hotRankActive.toString(),
Text('upvotes:'), 'published:': com.published.toString(),
Text(com.upvotes.toString()), 'updated': com.updated.toString(),
]), });
TableRow(children: [
Text('downvotes:'),
Text(com.downvotes.toString()),
]),
TableRow(children: [
Text('score:'),
Text(com.score.toString()),
]),
TableRow(children: [
Text('% of upvotes:'),
Text(
'''${(100 * (com.upvotes / (com.upvotes + com.downvotes))).toInt()}%'''),
]),
TableRow(children: [
Text('hotrank:'),
Text(com.hotRank.toString()),
]),
TableRow(children: [
Text('hotrank active:'),
Text(com.hotRankActive.toString()),
]),
TableRow(children: [
Text('published:'),
Text('''${DateFormat.yMMMd().format(com.published)}'''
''' ${DateFormat.Hms().format(com.published)}'''),
]),
TableRow(children: [
Text('updated:'),
Text(com.updated != null
? '''${DateFormat.yMMMd().format(com.updated)}'''
''' ${DateFormat.Hms().format(com.updated)}'''
: 'never'),
]),
],
),
]));
} }
bool get isOP => commentTree.comment.creatorId == postCreatorId; bool get isOP => commentTree.comment.creatorId == postCreatorId;

View File

@ -17,6 +17,7 @@ import '../util/extensions/api.dart';
import '../util/goto.dart'; import '../util/goto.dart';
import 'bottom_modal.dart'; import 'bottom_modal.dart';
import 'fullscreenable_image.dart'; import 'fullscreenable_image.dart';
import 'info_table_popup.dart';
import 'markdown_text.dart'; import 'markdown_text.dart';
import 'save_post_button.dart'; import 'save_post_button.dart';
@ -73,59 +74,21 @@ class Post extends HookWidget {
leading: Icon(Icons.info_outline), leading: Icon(Icons.info_outline),
title: Text('Nerd stuff'), title: Text('Nerd stuff'),
onTap: () { onTap: () {
showDialog( showInfoTablePopup(context, {
context: context, 'id:': post.id.toString(),
child: SimpleDialog( 'apId:': post.apId,
contentPadding: const EdgeInsets.symmetric( 'upvotes:': post.upvotes.toString(),
horizontal: 20, 'downvotes:': post.downvotes.toString(),
vertical: 15, 'score': post.score.toString(),
), '% of upvotes:':
children: [ '''${(100 * (post.upvotes / (post.upvotes + post.downvotes))).toInt()}%''',
Table( 'hotRank:': post.hotRank.toString(),
children: [ 'hotRank active': post.hotRankActive.toString(),
TableRow(children: [ 'local:': post.local.toString(),
Text('upvotes:'), 'published:': post.published.toString(),
Text(post.upvotes.toString()), 'updated': post.updated?.toString() ?? 'never',
]), 'newestActivityTime:': post.newestActivityTime.toString(),
TableRow(children: [ });
Text('downvotes:'),
Text(post.downvotes.toString()),
]),
TableRow(children: [
Text('score:'),
Text(post.score.toString()),
]),
TableRow(children: [
Text('% of upvotes:'),
Text(
'''${(100 * (post.upvotes / (post.upvotes + post.downvotes))).toInt()}%'''),
]),
TableRow(children: [
Text('hotrank:'),
Text(post.hotRank.toString()),
]),
TableRow(children: [
Text('hotrank active:'),
Text(post.hotRankActive.toString()),
]),
TableRow(children: [
Text('published:'),
Text(
'''${DateFormat.yMMMd().format(post.published)}'''
''' ${DateFormat.Hms().format(post.published)}'''),
]),
TableRow(children: [
Text('updated:'),
Text(post.updated != null
? '''${DateFormat.yMMMd().format(post.updated)}'''
''' ${DateFormat.Hms().format(post.updated)}'''
: 'never'),
]),
],
),
],
),
);
}, },
), ),
], ],