forked from eatvio/eatvio_app
internet connection handling
This commit is contained in:
@@ -25,9 +25,28 @@ class DevToolsScreenContent extends StatefulWidget {
|
||||
|
||||
class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
|
||||
String baseUrlForTest = '';
|
||||
final List<TestCases> testCases = [Test850task(), GetChatRoomPreviews(), GetChatRoom(), SendMessage(), GetChatMessages(), GetChatRoomIdByUserSlug()];
|
||||
final List<TestCases> testCases = [
|
||||
Test850task(),
|
||||
GetChatRoomPreviews(),
|
||||
GetChatRoom(),
|
||||
SendMessage(),
|
||||
GetChatMessages(),
|
||||
GetChatRoomIdByUserSlug(),
|
||||
GetBlogPostList(),
|
||||
GetRecipes(),
|
||||
GetDiets(),
|
||||
GetPlans(),
|
||||
GetBlogPostComments(),
|
||||
SendBlogPostComment(),
|
||||
GetDietsComments(),
|
||||
SendDietsComment(),
|
||||
GetPlansComments(),
|
||||
SendPlansComment(),
|
||||
GetRecipesComments(),
|
||||
];
|
||||
final controller = TextEditingController();
|
||||
late final List<TestState> testsStates;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -40,7 +59,6 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
@@ -73,76 +91,89 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
if (baseUrlForTest != baseUrl)
|
||||
CustomOutlinedButton(
|
||||
text: 'Set dev2 base url',
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
this.baseUrlForTest = baseUrl;
|
||||
});
|
||||
},
|
||||
buttonStyle: ButtonStyle(),
|
||||
),
|
||||
SizedBox(
|
||||
height: baseUrlForTest != baseUrl ? 40 : 10,
|
||||
),
|
||||
if (baseUrlForTest != 'https://eatvio.ru')
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: testCases.length,
|
||||
itemBuilder: (context, index) => Row(
|
||||
children: [
|
||||
Text('${index + 1}. ${testCases[index].name}'),
|
||||
SizedBox(
|
||||
width: 50,
|
||||
),
|
||||
Expanded(
|
||||
child: CustomOutlinedButton(
|
||||
text: 'run',
|
||||
height: 20,
|
||||
width: 60,
|
||||
onPressed: () async {
|
||||
if (testsStates[index] == TestState.loading) return;
|
||||
|
||||
setState(() {
|
||||
testsStates[index] = TestState.loading;
|
||||
});
|
||||
final result = await testCases[index].run(baseUrl: baseUrlForTest);
|
||||
if (result) {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.success;
|
||||
});
|
||||
showSuccessToast('${testCases[index].name} passed');
|
||||
} else {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.fail;
|
||||
});
|
||||
showErrorToast('${testCases[index].name} failed');
|
||||
}
|
||||
},
|
||||
buttonStyle: ButtonStyle(),
|
||||
itemBuilder: (context, index) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text('${index + 1}. ${testCases[index].name}'),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 30,
|
||||
),
|
||||
switch (testsStates[index]) {
|
||||
TestState.success => Expanded(
|
||||
child: Container(
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CustomOutlinedButton(
|
||||
text: 'run',
|
||||
height: 20,
|
||||
color: Colors.green,
|
||||
width: 60,
|
||||
onPressed: () async {
|
||||
if (testsStates[index] == TestState.loading) return;
|
||||
|
||||
setState(() {
|
||||
testsStates[index] = TestState.loading;
|
||||
});
|
||||
final result = await testCases[index].run(baseUrl: baseUrlForTest);
|
||||
if (result) {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.success;
|
||||
});
|
||||
showSuccessToast('${testCases[index].name} passed');
|
||||
} else {
|
||||
setState(() {
|
||||
testsStates[index] = TestState.fail;
|
||||
});
|
||||
showErrorToast('${testCases[index].name} failed');
|
||||
}
|
||||
},
|
||||
buttonStyle: ButtonStyle(),
|
||||
),
|
||||
),
|
||||
TestState.fail => Expanded(
|
||||
child: Container(
|
||||
height: 20,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
TestState.notRun => Expanded(
|
||||
child: Container(
|
||||
height: 20,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
TestState.loading => Expanded(
|
||||
child: Container(
|
||||
height: 20,
|
||||
child: SizedBox(height: 20, width: 20, child: Center(child: CircularProgressIndicator())),
|
||||
),
|
||||
),
|
||||
},
|
||||
],
|
||||
SizedBox(width: 5),
|
||||
switch (testsStates[index]) {
|
||||
TestState.success => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
color: Colors.green,
|
||||
),
|
||||
TestState.fail => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
color: Colors.red,
|
||||
),
|
||||
TestState.notRun => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
color: Colors.grey,
|
||||
),
|
||||
TestState.loading => Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: SizedBox(height: 20, width: 20, child: Center(child: CircularProgressIndicator())),
|
||||
),
|
||||
},
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user