kopia lustrzana https://gitlab.com/mysocialportal/relatica
				
				
				
			
		
			
				
	
	
		
			125 wiersze
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Dart
		
	
	
			
		
		
	
	
			125 wiersze
		
	
	
		
			4.1 KiB
		
	
	
	
		
			Dart
		
	
	
| import 'package:flutter/material.dart';
 | |
| import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
 | |
| import 'package:result_monad/result_monad.dart';
 | |
| 
 | |
| import '../controls/padding.dart';
 | |
| import '../friendica_client.dart';
 | |
| import '../globals.dart';
 | |
| import '../models/exec_error.dart';
 | |
| import '../models/timeline_entry.dart';
 | |
| import '../services/auth_service.dart';
 | |
| 
 | |
| class HomeScreen extends StatelessWidget {
 | |
|   final postText = TextEditingController();
 | |
| 
 | |
|   @override
 | |
|   Widget build(BuildContext context) {
 | |
|     final clientResult = getIt<AuthService>().currentClient;
 | |
|     final body = clientResult.fold(onSuccess: (client) {
 | |
|       return Column(
 | |
|         children: [
 | |
|           TextFormField(
 | |
|             controller: postText,
 | |
|             maxLines: 4,
 | |
|             decoration: InputDecoration(
 | |
|               border: OutlineInputBorder(
 | |
|                 borderSide: BorderSide(
 | |
|                   color: Theme.of(context).backgroundColor,
 | |
|                 ),
 | |
|                 borderRadius: BorderRadius.circular(5.0),
 | |
|               ),
 | |
|             ),
 | |
|           ),
 | |
|           const VerticalPadding(),
 | |
|           ElevatedButton(onPressed: null, child: const Text('Post')),
 | |
|           const VerticalPadding(),
 | |
|           Expanded(child: buildTimelineComponent(context, client))
 | |
|         ],
 | |
|       );
 | |
|     }, onError: (error) {
 | |
|       return Center(
 | |
|         child: Column(
 | |
|           mainAxisAlignment: MainAxisAlignment.center,
 | |
|           children: [
 | |
|             Text('Error getting client: $error '),
 | |
|           ],
 | |
|         ),
 | |
|       );
 | |
|     });
 | |
| 
 | |
|     return Scaffold(
 | |
|       appBar: AppBar(
 | |
|         title: Text('Home'),
 | |
|       ),
 | |
|       body: body,
 | |
|     );
 | |
|   }
 | |
| 
 | |
|   Widget buildTimelineComponent(BuildContext context, FriendicaClient client) {
 | |
|     return FutureBuilder<Result<List<TimelineEntry>, ExecError>>(
 | |
|         future: client.getHomeTimeline(page: 1, count: 50),
 | |
|         builder: (context, snapshot) {
 | |
|           if (snapshot.connectionState != ConnectionState.done) {
 | |
|             return Text('Loading');
 | |
|           }
 | |
| 
 | |
|           if (snapshot.hasError) {
 | |
|             return Text('Got an error: ${snapshot.error}');
 | |
|           }
 | |
| 
 | |
|           if (snapshot.data == null) {
 | |
|             return Text('Got null data');
 | |
|           }
 | |
| 
 | |
|           final result = snapshot.data!;
 | |
|           if (result.isFailure) {
 | |
|             return Text('Got an error: ${result.error}');
 | |
|           }
 | |
| 
 | |
|           final items = result.value;
 | |
| 
 | |
|           return ListView.separated(
 | |
|             itemBuilder: (context, index) {
 | |
|               final item = items[index];
 | |
|               return ListTile(
 | |
|                 subtitle: Padding(
 | |
|                   padding: const EdgeInsets.all(8.0),
 | |
|                   child: Column(
 | |
|                     mainAxisAlignment: MainAxisAlignment.start,
 | |
|                     crossAxisAlignment: CrossAxisAlignment.start,
 | |
|                     children: [
 | |
|                       HtmlWidget(
 | |
|                         item.body,
 | |
|                         onTapUrl: (url) async {
 | |
|                           print(url);
 | |
|                           return true;
 | |
|                         },
 | |
|                         onTapImage: (imageMetadata) {
 | |
|                           print(imageMetadata);
 | |
|                         },
 | |
|                       ),
 | |
|                       if (item.links.isNotEmpty)
 | |
|                         Text('Preview: ${item.links.first.url}'),
 | |
|                       if (item.mediaAttachments.isNotEmpty)
 | |
|                         ...item.mediaAttachments
 | |
|                             .map((a) => Text('Media: ${a.uri}')),
 | |
|                       Text(
 | |
|                           'Engagement -- Likes: ${item.likes.length}, Dislikes: ${item.dislikes.length}, ')
 | |
|                     ],
 | |
|                   ),
 | |
|                 ),
 | |
|                 //trailing: Text(item.parentId),
 | |
|                 title: Text(
 | |
|                     '${item.id} for ${item.author} for post ${item.parentId}'),
 | |
|                 trailing: Text(DateTime.fromMillisecondsSinceEpoch(
 | |
|                         item.creationTimestamp * 1000)
 | |
|                     .toIso8601String()),
 | |
|               );
 | |
|             },
 | |
|             separatorBuilder: (context, index) => Divider(),
 | |
|             itemCount: items.length,
 | |
|           );
 | |
|         });
 | |
|   }
 | |
| }
 |