LCOV - code coverage report
Current view: top level - lib/views - filesharingview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 38 0.0 %
Date: 2024-09-24 21:50:54 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:convert';
       2             : 
       3             : import 'package:cwtch/main.dart';
       4             : import 'package:cwtch/models/contact.dart';
       5             : import 'package:cwtch/models/profile.dart';
       6             : import 'package:cwtch/settings.dart';
       7             : import 'package:flutter/material.dart';
       8             : import 'package:provider/provider.dart';
       9             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
      10             : import 'package:scrollable_positioned_list/scrollable_positioned_list.dart';
      11             : 
      12             : import '../cwtch_icons_icons.dart';
      13             : 
      14             : class FileSharingView extends StatefulWidget {
      15           0 :   @override
      16           0 :   _FileSharingViewState createState() => _FileSharingViewState();
      17             : }
      18             : 
      19             : class _FileSharingViewState extends State<FileSharingView> {
      20           0 :   @override
      21             :   Widget build(BuildContext context) {
      22           0 :     var handle = Provider.of<ContactInfoState>(context).nickname;
      23           0 :     if (handle.isEmpty) {
      24           0 :       handle = Provider.of<ContactInfoState>(context).onion;
      25             :     }
      26             : 
      27           0 :     var profileHandle = Provider.of<ProfileInfoState>(context).onion;
      28             : 
      29           0 :     return Scaffold(
      30           0 :       appBar: AppBar(
      31           0 :         title: Text(handle + " ยป " + AppLocalizations.of(context)!.manageSharedFiles),
      32             :       ),
      33           0 :       body: FutureBuilder(
      34           0 :         future: Provider.of<FlwtchState>(context, listen: false).cwtch.GetSharedFiles(profileHandle, Provider.of<ContactInfoState>(context).identifier),
      35           0 :         builder: (context, snapshot) {
      36           0 :           if (snapshot.hasData) {
      37           0 :             List<dynamic> sharedFiles = jsonDecode(snapshot.data as String) ?? List<dynamic>.empty();
      38           0 :             sharedFiles.sort((a, b) {
      39           0 :               return a["DateShared"].toString().compareTo(b["DateShared"].toString());
      40             :             });
      41             : 
      42           0 :             var fileList = ScrollablePositionedList.separated(
      43           0 :               itemScrollController: ItemScrollController(),
      44           0 :               itemCount: sharedFiles.length,
      45             :               shrinkWrap: true,
      46             :               reverse: true,
      47           0 :               physics: BouncingScrollPhysics(),
      48           0 :               semanticChildCount: sharedFiles.length,
      49           0 :               itemBuilder: (context, index) {
      50           0 :                 String filekey = sharedFiles[index]["FileKey"];
      51             :                 // This makes the UI *very* slow when enabled. But can be useful for debugging
      52             :                 // Uncomment if necessary.
      53             :                 // EnvironmentConfig.debugLog("$sharedFiles " + sharedFiles[index].toString());
      54           0 :                 return SwitchListTile(
      55           0 :                     title: Text(sharedFiles[index]["Path"]),
      56           0 :                     subtitle: Text(sharedFiles[index]["DateShared"]),
      57           0 :                     value: sharedFiles[index]["Active"],
      58           0 :                     activeTrackColor: Provider.of<Settings>(context).theme.defaultButtonColor,
      59           0 :                     inactiveTrackColor: Provider.of<Settings>(context).theme.defaultButtonDisabledColor,
      60           0 :                     secondary: Icon(CwtchIcons.attached_file_3, color: Provider.of<Settings>(context).current().mainTextColor),
      61           0 :                     onChanged: (newValue) {
      62           0 :                       setState(() {
      63             :                         if (newValue) {
      64           0 :                           Provider.of<FlwtchState>(context, listen: false).cwtch.RestartSharing(profileHandle, filekey);
      65             :                         } else {
      66           0 :                           Provider.of<FlwtchState>(context, listen: false).cwtch.StopSharing(profileHandle, filekey);
      67             :                         }
      68             :                       });
      69             :                     });
      70             :               },
      71           0 :               separatorBuilder: (BuildContext context, int index) {
      72           0 :                 return Divider(height: 1);
      73             :               },
      74             :             );
      75             :             return fileList;
      76             :           }
      77           0 :           return Container();
      78             :         },
      79             :       ),
      80             :     );
      81             :   }
      82             : }

Generated by: LCOV version 1.14