Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable action button and validation #58

54 changes: 30 additions & 24 deletions lib/screens/mobile/mobile_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
}

Widget _buildTabActionDropdown(int index) {
double baseHeight = 60;
double pixelDensity = MediaQuery.of(context).devicePixelRatio;
double buttonHeight = baseHeight / pixelDensity;
return Padding(
padding: const EdgeInsets.only(left: 15, right: 15, top: 5),
child: Row(
Expand All @@ -388,33 +391,36 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
Expanded(
child: Padding(
padding: const EdgeInsets.only(right: 10),
child: TextFormField(
controller: _tabData[index].linkController,
decoration: const InputDecoration(
hintText: "ws://localhost:8080/ws",
hintStyle: TextStyle(fontWeight: FontWeight.w200),
labelText: "Enter URL here",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
child: SizedBox(
height: buttonHeight,
child: TextFormField(
controller: _tabData[index].linkController,
decoration: const InputDecoration(
hintText: "ws://localhost:8080/ws",
hintStyle: TextStyle(fontWeight: FontWeight.w200),
labelText: "Enter URL here",
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
),
contentPadding: EdgeInsets.all(25),
),
contentPadding: EdgeInsets.all(10),
validator: (value) {
if (value == null || value.isEmpty) {
return "URL cannot be empty";
}
const urlPattern = r"^(ws|wss):\/\/[^\s$.?#]+(\.[^\s$.?#]+)*(:\d+)?(\/[^\s]*)?$";
final result = RegExp(urlPattern, caseSensitive: false).hasMatch(value);
if (!result) {
return "Enter a valid WebSocket URL";
}
return null; // return null if the validation passes
},
),
validator: (value) {
if (value == null || value.isEmpty) {
return "URL cannot be empty";
}
const urlPattern = r"^(ws|wss):\/\/[^\s$.?#]+(\.[^\s$.?#]+)*(:\d+)?(\/[^\s]*)?$";
final result = RegExp(urlPattern, caseSensitive: false).hasMatch(value);
if (!result) {
return "Enter a valid WebSocket URL";
}
return null; // return null if the validation passes
},
),
),
),
sendButton(_tabData[index].sendButtonText, index),
Container(width: 1, height: 45, color: Colors.black),
Container(width: 1, height: buttonHeight, color: Colors.black),
if (_tabData[index].sendButtonText == "UnRegister" || _tabData[index].sendButtonText == "UnSubscribe")
InkWell(
onTap: () {
Expand All @@ -427,7 +433,7 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
},
child: Container(
padding: const EdgeInsets.all(8),
height: 45,
height: buttonHeight,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
Expand All @@ -443,7 +449,7 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
)
else
Container(
height: 45,
height: buttonHeight,
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(10),
Expand Down Expand Up @@ -662,7 +668,7 @@ class _MobileHomeScaffoldState extends State<MobileHomeScaffold> with TickerProv
Widget sendButton(String sendButton, int index) {
var sessionStateProvider = Provider.of<SessionStateProvider>(context, listen: false);
final scaffoldMessenger = ScaffoldMessenger.of(context);
double baseHeight = 45;
double baseHeight = 60;
double baseWidth = 150;
double pixelDensity = MediaQuery.of(context).devicePixelRatio;
double buttonHeight = baseHeight / pixelDensity;
Expand Down