LCOV - code coverage report
Current view: top level - lib/widgets - folderpicker.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 30 0.0 %
Date: 2024-08-22 16:58:37 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/controllers/filesharing.dart';
       2             : import 'package:cwtch/models/appstate.dart';
       3             : import 'package:flutter/material.dart';
       4             : import 'dart:io';
       5             : import 'package:provider/provider.dart';
       6             : import '../settings.dart';
       7             : import 'buttontextfield.dart';
       8             : import 'package:path/path.dart' as path;
       9             : 
      10             : class CwtchFolderPicker extends StatefulWidget {
      11             :   final String label;
      12             :   final String initialValue;
      13             :   final String tooltip;
      14             :   final String description;
      15             :   final Function(String)? onSave;
      16             :   final Key? testKey;
      17             :   final TextStyle? textStyle;
      18             :   final IconData icon;
      19           0 :   const CwtchFolderPicker({Key? key, this.testKey, this.textStyle, this.label = "", this.tooltip = "", this.initialValue = "", this.onSave, this.description = "", this.icon = Icons.file_download})
      20           0 :       : super(key: key);
      21             : 
      22           0 :   @override
      23           0 :   _CwtchFolderPickerState createState() => _CwtchFolderPickerState();
      24             : }
      25             : 
      26             : class _CwtchFolderPickerState extends State<CwtchFolderPicker> {
      27             :   final TextEditingController ctrlrVal = TextEditingController();
      28             : 
      29           0 :   @override
      30             :   void initState() {
      31           0 :     super.initState();
      32           0 :     ctrlrVal.text = widget.initialValue;
      33             :   }
      34             : 
      35           0 :   @override
      36             :   Widget build(BuildContext context) {
      37           0 :     return ListTile(
      38           0 :         leading: Icon(widget.icon, color: Provider.of<Settings>(context).theme.messageFromMeTextColor),
      39           0 :         title: Text(widget.label),
      40           0 :         subtitle: Text(widget.description),
      41           0 :         trailing: Container(
      42           0 :             width: MediaQuery.of(context).size.width / 4,
      43           0 :             child: CwtchButtonTextField(
      44           0 :               testKey: widget.testKey,
      45           0 :               controller: ctrlrVal,
      46           0 :               textStyle: widget.textStyle,
      47           0 :               readonly: Platform.isAndroid,
      48           0 :               onPressed: Provider.of<AppState>(context).disableFilePicker
      49             :                   ? null
      50           0 :                   : () async {
      51           0 :                       if (Platform.isAndroid) {
      52             :                         return;
      53             :                       }
      54             : 
      55           0 :                       var selectedDirectory = await showSelectDirectoryPicker(context);
      56             :                       if (selectedDirectory != null) {
      57             :                         //File directory = File(selectedDirectory);
      58           0 :                         selectedDirectory += path.separator;
      59           0 :                         ctrlrVal.text = selectedDirectory;
      60           0 :                         if (widget.onSave != null) {
      61           0 :                           widget.onSave!(selectedDirectory);
      62             :                         }
      63             :                       } else {
      64             :                         // User canceled the picker
      65             :                       }
      66             :                     },
      67           0 :               onChanged: widget.onSave,
      68           0 :               icon: Icon(Icons.folder),
      69           0 :               tooltip: widget.tooltip,
      70             :             )));
      71             :   }
      72             : }

Generated by: LCOV version 1.14