relatica/lib/screens/post_screen.dart

82 wiersze
2.5 KiB
Dart
Czysty Zwykły widok Historia

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:provider/provider.dart';
import '../controls/linear_status_indicator.dart';
import '../controls/responsive_max_width.dart' show ResponsiveMaxWidth;
import '../controls/standard_appbar.dart';
import '../controls/timeline/post_control.dart';
import '../globals.dart';
import '../riverpod_controllers/entry_tree_item_services.dart';
import '../services/auth_service.dart';
import '../services/network_status_service.dart';
class PostScreen extends ConsumerStatefulWidget {
final String id;
final String goToId;
const PostScreen({
super.key,
required this.id,
required this.goToId,
});
@override
ConsumerState<PostScreen> createState() => _PostScreenState();
}
class _PostScreenState extends ConsumerState<PostScreen> {
bool firstDraw = true;
@override
void initState() {
2024-07-26 14:15:24 +00:00
super.initState();
final profile = context.read<AccountsService>().currentProfile;
Future.delayed(const Duration(milliseconds: 100), () async {
await ref
.read(timelineUpdaterProvider(profile).notifier)
.refreshStatusChain(widget.id);
});
}
@override
Widget build(BuildContext context) {
final nss = getIt<NetworkStatusService>();
final profile = context.watch<AccountsService>().currentProfile;
final entryResult =
ref.watch(postTreeEntryByIdProvider(profile, widget.id));
final body = entryResult.fold(
onSuccess: (post) => RefreshIndicator(
onRefresh: () async {
await ref
.read(timelineUpdaterProvider(profile).notifier)
.refreshStatusChain(widget.id);
return;
},
child: PostControl(
id: post.id,
scrollToId: widget.goToId,
openRemote: true,
2023-03-20 02:16:30 +00:00
showStatusOpenButton: false,
isRoot: true,
),
),
onError: (error) => Text(firstDraw || nss.timelineLoadingStatus.value
? 'Attempting to load post'
: 'Error getting post: $error'));
firstDraw = true;
return Scaffold(
appBar: StandardAppBar.build(context, 'View Post', actions: []),
body: Padding(
padding: const EdgeInsets.all(0.0),
child: Column(
children: [
StandardLinearProgressIndicator(nss.timelineLoadingStatus),
Expanded(child: ResponsiveMaxWidth(child: body)),
],
),
));
}
}