From 1f40c30778ea30adfcb5251a032e49d015d22624 Mon Sep 17 00:00:00 2001 From: Hiddify Date: Sat, 10 Feb 2024 18:28:40 +0100 Subject: [PATCH] make ip anonymous --- .../proxy/active/active_proxy_footer.dart | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/lib/features/proxy/active/active_proxy_footer.dart b/lib/features/proxy/active/active_proxy_footer.dart index 55102a11..ef175940 100644 --- a/lib/features/proxy/active/active_proxy_footer.dart +++ b/lib/features/proxy/active/active_proxy_footer.dart @@ -92,10 +92,7 @@ class _InfoProp extends StatelessWidget { required IconData icon, required String text, }) : icon = Icon(icon), - child = Text( - text, - overflow: TextOverflow.ellipsis, - ), + child = IPWidget(text), isLoading = false; _InfoProp.flag({ @@ -107,10 +104,7 @@ class _InfoProp extends StatelessWidget { padding: const EdgeInsets.all(2), child: CircleFlag(countryCode), ), - child = Text( - text, - overflow: TextOverflow.ellipsis, - ), + child = IPWidget(text), isLoading = false; _InfoProp.loading({ @@ -147,3 +141,47 @@ class _InfoProp extends StatelessWidget { ); } } + +class IPWidget extends StatefulWidget { + final String text1; + final String text2; + + IPWidget(String text) + : text1 = _replaceMiddlePart(text), + text2 = text, + super(key: UniqueKey()); + static String _replaceMiddlePart(String ip) { + RegExp regex = RegExp( + r'^([\da-f]+([:.]))([\da-f:.]*)([:.][\da-f]+)$', + caseSensitive: false, + ); + + return ip.replaceAllMapped(regex, (match) { + return '${match[1]} ░ ${match[2]} ░ ${match[4]}'; + }); + } + + @override + _IPWidgetState createState() => _IPWidgetState(); +} + +class _IPWidgetState extends State { + bool isText1Visible = true; + + void toggleVisibility() { + setState(() { + isText1Visible = !isText1Visible; + }); + } + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: toggleVisibility, + child: Text( + isText1Visible ? widget.text1 : widget.text2, + overflow: TextOverflow.ellipsis, + ), + ); + } +}