TestCaseView.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. import 'package:flutter/material.dart';
  2. import 'package:ustest/Services/TestCase.dart';
  3. class TestCaseView extends StatelessWidget {
  4. const TestCaseView();
  5. @override
  6. Widget build(BuildContext context) {
  7. print("build TestCaseView");
  8. var tests = fetchTestCases();
  9. return Scaffold(
  10. body: Container(
  11. child: Column(
  12. children: [
  13. Padding(
  14. padding: EdgeInsets.all(8.0),
  15. child: Row(
  16. children: [
  17. IconButton(icon: Icon(Icons.play_circle_fill), onPressed: onRun)
  18. ],
  19. ),
  20. ),
  21. Padding(
  22. padding: EdgeInsets.all(8.0),
  23. child: Table(
  24. columnWidths: const <int, TableColumnWidth>{
  25. 0: FlexColumnWidth(50.0),
  26. 1: FixedColumnWidth(100.0),
  27. 2: FlexColumnWidth(80.0),
  28. 3: FlexColumnWidth(250.0),
  29. },
  30. border: TableBorder.all(
  31. color: Colors.green, width: 1.0, style: BorderStyle.solid),
  32. children: [
  33. TableRow(
  34. decoration: BoxDecoration(color: Colors.grey[200]),
  35. children: [
  36. Checkbox(value: false, onChanged: onSelectAllChanged),
  37. Text("URL",
  38. style: TextStyle(
  39. color: Colors.amber[900],
  40. backgroundColor: Colors.grey[200],
  41. fontSize: 16)),
  42. Text("METHOD"),
  43. Text("BODY")
  44. ],
  45. ),
  46. for (var i = 0; i < tests.length; i++)
  47. TableRow(
  48. children: [
  49. Checkbox(
  50. value: false,
  51. onChanged: (bool? value) {},
  52. ),
  53. Text(tests[i].url),
  54. Text(tests[i].method),
  55. Text(tests[i].body)
  56. ],
  57. )
  58. ],
  59. ),
  60. ),
  61. ],
  62. )),
  63. );
  64. }
  65. List<TestCase> fetchTestCases() {
  66. try {
  67. return <TestCase>[];
  68. var testCases = <TestCase>[];
  69. testCases.add(new TestCase(
  70. id: "1",
  71. url: "http://192.168.6.80:8303/IPatientService",
  72. method: "POST",
  73. body: '"{'
  74. '"jsonrpc": "2.0"'
  75. '"method": "FindPatients",'
  76. '"params": ['
  77. '{'
  78. '"Token": "1e8605f8991f423d9958196e21528b08",'
  79. '"KeyWord": "",'
  80. '"PageIndex": 1,'
  81. '"PageSize": 10'
  82. '}'
  83. '],'
  84. '"id": 1'
  85. '}"'));
  86. return testCases;
  87. } catch (ex) {
  88. print(ex);
  89. }
  90. return <TestCase>[];
  91. }
  92. void onAdd() {}
  93. void onRun() {}
  94. void onSelectAllChanged(bool? value) {}
  95. }
  96. class TestCaseList extends StatelessWidget {
  97. const TestCaseList({Key? key, required this.testCases}) : super(key: key);
  98. final List<TestCase> testCases;
  99. @override
  100. Widget build(BuildContext context) {
  101. return Scaffold(
  102. body: Scrollbar(
  103. child: ListView(
  104. restorationId: 'list_demo_list_view',
  105. padding: const EdgeInsets.symmetric(vertical: 0),
  106. children: [],
  107. ),
  108. ),
  109. );
  110. }
  111. }
  112. class Counter extends StatefulWidget {
  113. final testCase;
  114. Counter(this.testCase);
  115. @override
  116. _CounterState createState() => _CounterState();
  117. }
  118. class _CounterState extends State<Counter> {
  119. int qty = 0;
  120. @override
  121. Widget build(BuildContext context) {
  122. return Row(
  123. mainAxisAlignment: MainAxisAlignment.center,
  124. children: [
  125. Container(
  126. width: 30,
  127. child: TextButton(
  128. style: ButtonStyle(
  129. backgroundColor: MaterialStateProperty.resolveWith((states) {
  130. //设置按下时的背景颜色
  131. if (states.contains(MaterialState.pressed)) {
  132. return Colors.blue[200];
  133. }
  134. //默认不使用背景颜色
  135. return null;
  136. }),
  137. ),
  138. onPressed: () async {
  139. var productItem = widget.testCase;
  140. if (qty > 0) {
  141. setState(() {
  142. qty--;
  143. productItem.qty = qty;
  144. });
  145. }
  146. },
  147. child: Text(
  148. '-',
  149. style: TextStyle(color: Colors.amber[900]),
  150. ),
  151. )),
  152. Text('$qty', style: TextStyle(color: Colors.black, fontSize: 12)),
  153. Container(
  154. width: 30,
  155. child: TextButton(
  156. onPressed: () async {
  157. //var productItem = widget.testCase as TestCase;
  158. if (qty < 100) {
  159. setState(() {
  160. qty++;
  161. });
  162. }
  163. },
  164. child: Text(
  165. '+',
  166. style: TextStyle(color: Colors.amber[900]),
  167. ),
  168. )),
  169. ],
  170. );
  171. }
  172. }