Line data Source code
1 : import 'package:cwtch/models/servers.dart';
2 : import 'package:cwtch/themes/opaque.dart';
3 : import 'package:cwtch/views/addeditservers.dart';
4 : import 'package:flutter/material.dart';
5 : import 'package:flutter/services.dart';
6 : import 'package:provider/provider.dart';
7 : import 'package:cwtch/l10n/app_localizations.dart';
8 :
9 : import '../cwtch_icons_icons.dart';
10 : import '../errorHandler.dart';
11 : import '../settings.dart';
12 :
13 : class ServerRow extends StatefulWidget {
14 0 : @override
15 0 : _ServerRowState createState() => _ServerRowState();
16 : }
17 :
18 : class _ServerRowState extends State<ServerRow> {
19 0 : @override
20 : Widget build(BuildContext context) {
21 0 : var server = Provider.of<ServerInfoState>(context);
22 0 : return InkWell(
23 : enableFeedback: true,
24 : splashFactory: InkSplash.splashFactory,
25 0 : child: Ink(
26 : color: Colors.transparent,
27 0 : child: Container(
28 0 : child: Row(
29 : mainAxisAlignment: MainAxisAlignment.spaceBetween,
30 0 : children: [
31 0 : Padding(
32 : padding: const EdgeInsets.all(6.0), //border size
33 0 : child: Row(
34 0 : children: [
35 0 : Icon(
36 : CwtchIcons.dns_24px,
37 0 : color: server.running ? Provider.of<Settings>(context).theme.portraitOnlineBorderColor : Provider.of<Settings>(context).theme.portraitOfflineBorderColor,
38 : size: 64,
39 : ),
40 0 : Visibility(
41 0 : visible: !server.running,
42 0 : child: Icon(CwtchIcons.negative_heart_24px, color: Provider.of<Settings>(context).theme.portraitOfflineBorderColor),
43 : ),
44 : ],
45 : ),
46 : ),
47 0 : Expanded(
48 0 : child: Column(
49 0 : children: [
50 0 : Text(
51 0 : server.description,
52 0 : semanticsLabel: server.description,
53 0 : style: Provider.of<Settings>(context)
54 0 : .scaleFonts(defaultFormLabelTextStyle)
55 0 : .apply(color: server.running ? Provider.of<Settings>(context).theme.portraitOnlineBorderColor : Provider.of<Settings>(context).theme.portraitOfflineBorderColor),
56 : softWrap: true,
57 : overflow: TextOverflow.ellipsis,
58 : ),
59 0 : Visibility(
60 0 : visible: !Provider.of<Settings>(context).streamerMode,
61 0 : child: ExcludeSemantics(
62 0 : child: Text(
63 0 : server.onion,
64 : softWrap: true,
65 : overflow: TextOverflow.ellipsis,
66 0 : style: Provider.of<Settings>(context)
67 0 : .scaleFonts(defaultFormLabelTextStyle)
68 0 : .copyWith(color: server.running ? Provider.of<Settings>(context).theme.portraitOnlineBorderColor : Provider.of<Settings>(context).theme.portraitOfflineBorderColor),
69 : ),
70 : ),
71 : ),
72 : ],
73 : ),
74 : ),
75 :
76 : // Copy server button
77 0 : IconButton(
78 : enableFeedback: true,
79 0 : splashRadius: Material.defaultSplashRadius / 2,
80 0 : tooltip: AppLocalizations.of(context)!.copyServerKeys,
81 0 : icon: Icon(CwtchIcons.address_copy, color: Provider.of<Settings>(context).current().mainTextColor),
82 0 : onPressed: () {
83 0 : Clipboard.setData(new ClipboardData(text: server.serverBundle));
84 0 : final snackBar = SnackBar(content: Text(AppLocalizations.of(context)!.copiedToClipboardNotification));
85 0 : ScaffoldMessenger.of(context).showSnackBar(snackBar);
86 : },
87 : ),
88 :
89 : // Edit button
90 0 : IconButton(
91 : enableFeedback: true,
92 0 : splashRadius: Material.defaultSplashRadius / 2,
93 0 : tooltip: AppLocalizations.of(context)!.editServerTitle,
94 0 : icon: Icon(Icons.create, color: Provider.of<Settings>(context).current().mainTextColor),
95 0 : onPressed: () {
96 0 : _pushEditServer(server);
97 : },
98 : ),
99 : ],
100 : ),
101 : ),
102 : ),
103 0 : onTap: () {
104 0 : _pushEditServer(server);
105 : },
106 : );
107 : }
108 :
109 0 : void _pushEditServer(ServerInfoState server) {
110 0 : Provider.of<ErrorHandler>(context, listen: false).reset();
111 0 : Navigator.of(context).push(
112 : //MaterialPageRoute<void>(
113 0 : PageRouteBuilder(
114 0 : settings: RouteSettings(name: "serveraddedit"),
115 0 : pageBuilder: (bcontext, a1, a2) {
116 0 : return MultiProvider(
117 0 : providers: [ChangeNotifierProvider.value(value: server)],
118 0 : child: AddEditServerView(),
119 : );
120 : },
121 0 : transitionsBuilder: (c, anim, a2, child) => FadeTransition(opacity: anim, child: child),
122 0 : transitionDuration: Duration(milliseconds: 200),
123 : ),
124 : );
125 : }
126 : }
|