LCOV - code coverage report
Current view: top level - lib/views - serversview.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 80 0.0 %
Date: 2024-08-27 16:31:36 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:cwtch/models/servers.dart';
       2             : import 'package:cwtch/views/addeditservers.dart';
       3             : import 'package:cwtch/widgets/passwordfield.dart';
       4             : import 'package:cwtch/widgets/serverrow.dart';
       5             : import 'package:flutter/material.dart';
       6             : import 'package:provider/provider.dart';
       7             : import 'package:flutter_gen/gen_l10n/app_localizations.dart';
       8             : 
       9             : import '../cwtch_icons_icons.dart';
      10             : import '../main.dart';
      11             : import '../settings.dart';
      12             : 
      13             : ///
      14             : class ServersView extends StatefulWidget {
      15           0 :   @override
      16           0 :   _ServersView createState() => _ServersView();
      17             : }
      18             : 
      19             : class _ServersView extends State<ServersView> {
      20             :   final ctrlrPassword = TextEditingController();
      21             : 
      22           0 :   @override
      23             :   void dispose() {
      24           0 :     ctrlrPassword.dispose();
      25           0 :     super.dispose();
      26             :   }
      27             : 
      28           0 :   @override
      29             :   Widget build(BuildContext context) {
      30           0 :     return Scaffold(
      31           0 :         backgroundColor: Provider.of<Settings>(context, listen: false).theme.backgroundMainColor,
      32           0 :         appBar: AppBar(
      33           0 :           title: Text(MediaQuery.of(context).size.width > 600 ? AppLocalizations.of(context)!.serversManagerTitleLong : AppLocalizations.of(context)!.serversManagerTitleShort),
      34           0 :           actions: getActions(),
      35             :         ),
      36           0 :         floatingActionButton: FloatingActionButton(
      37           0 :           onPressed: _pushAddServer,
      38           0 :           tooltip: AppLocalizations.of(context)!.addServerTooltip,
      39           0 :           child: Icon(
      40             :             Icons.add,
      41           0 :             semanticLabel: AppLocalizations.of(context)!.addServerTooltip,
      42           0 :             color: Provider.of<Settings>(context).theme.defaultButtonTextColor,
      43             :           ),
      44             :         ),
      45           0 :         body: Consumer<ServerListState>(
      46           0 :           builder: (context, svrs, child) {
      47           0 :             final tiles = svrs.servers.map(
      48           0 :               (ServerInfoState server) {
      49           0 :                 return ChangeNotifierProvider<ServerInfoState>.value(
      50             :                   value: server,
      51           0 :                   builder: (context, child) => RepaintBoundary(child: ServerRow()),
      52             :                 );
      53             :               },
      54             :             );
      55             : 
      56           0 :             final divided = ListTile.divideTiles(
      57             :               context: context,
      58             :               tiles: tiles,
      59           0 :             ).toList();
      60             : 
      61           0 :             if (tiles.isEmpty) {
      62           0 :               return Center(
      63           0 :                   child: Text(
      64           0 :                 AppLocalizations.of(context)!.unlockServerTip,
      65             :                 textAlign: TextAlign.center,
      66             :               ));
      67             :             }
      68             : 
      69           0 :             return ListView(children: divided);
      70             :           },
      71             :         ));
      72             :   }
      73             : 
      74           0 :   List<Widget> getActions() {
      75           0 :     List<Widget> actions = new List<Widget>.empty(growable: true);
      76             : 
      77             :     // Unlock Profiles
      78           0 :     actions.add(IconButton(
      79           0 :       icon: Icon(CwtchIcons.lock_open_24px),
      80           0 :       color: Provider.of<ServerListState>(context).servers.isEmpty ? Provider.of<Settings>(context).theme.defaultButtonColor : Provider.of<Settings>(context).theme.mainTextColor,
      81           0 :       tooltip: AppLocalizations.of(context)!.tooltipUnlockProfiles,
      82           0 :       onPressed: _modalUnlockServers,
      83             :     ));
      84             : 
      85             :     return actions;
      86             :   }
      87             : 
      88           0 :   void _modalUnlockServers() {
      89           0 :     showModalBottomSheet<void>(
      90           0 :         context: context,
      91             :         isScrollControlled: true,
      92           0 :         builder: (BuildContext context) {
      93           0 :           return Padding(
      94           0 :               padding: MediaQuery.of(context).viewInsets,
      95           0 :               child: RepaintBoundary(
      96           0 :                   child: Container(
      97             :                 height: 200, // bespoke value courtesy of the [TextField] docs
      98           0 :                 child: Center(
      99           0 :                     child: Padding(
     100           0 :                         padding: EdgeInsets.all(10.0),
     101           0 :                         child: Column(
     102             :                           mainAxisAlignment: MainAxisAlignment.center,
     103             :                           mainAxisSize: MainAxisSize.min,
     104           0 :                           children: <Widget>[
     105           0 :                             Text(AppLocalizations.of(context)!.enterServerPassword),
     106           0 :                             SizedBox(
     107             :                               height: 20,
     108             :                             ),
     109           0 :                             CwtchPasswordField(
     110             :                               autofocus: true,
     111           0 :                               controller: ctrlrPassword,
     112           0 :                               action: unlock,
     113           0 :                               validator: (value) {
     114             :                                 return null;
     115             :                               },
     116             :                             ),
     117           0 :                             SizedBox(
     118             :                               height: 20,
     119             :                             ),
     120           0 :                             Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
     121           0 :                               Spacer(),
     122           0 :                               Expanded(
     123           0 :                                   child: ElevatedButton(
     124           0 :                                 child: Text(AppLocalizations.of(context)!.unlock, semanticsLabel: AppLocalizations.of(context)!.unlock),
     125           0 :                                 onPressed: () {
     126           0 :                                   unlock(ctrlrPassword.value.text);
     127             :                                 },
     128             :                               )),
     129           0 :                               Spacer()
     130             :                             ]),
     131             :                           ],
     132             :                         ))),
     133             :               )));
     134             :         });
     135             :   }
     136             : 
     137           0 :   void unlock(String password) {
     138           0 :     Provider.of<FlwtchState>(context, listen: false).cwtch.LoadServers(password);
     139           0 :     ctrlrPassword.text = "";
     140           0 :     Navigator.pop(context);
     141             :   }
     142             : 
     143           0 :   void _pushAddServer() {
     144           0 :     Navigator.of(context).push(
     145           0 :       PageRouteBuilder(
     146           0 :         pageBuilder: (bcontext, a1, a2) {
     147           0 :           return MultiProvider(
     148           0 :             providers: [
     149           0 :               ChangeNotifierProvider<ServerInfoState>(
     150           0 :                 create: (_) => ServerInfoState(onion: "", serverBundle: "", description: "", autoStart: true, running: false, isEncrypted: true),
     151             :               )
     152             :             ],
     153           0 :             child: AddEditServerView(),
     154             :           );
     155             :         },
     156           0 :         transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
     157           0 :         transitionDuration: Duration(milliseconds: 200),
     158             :       ),
     159             :     );
     160             :   }
     161             : }

Generated by: LCOV version 1.14