BuildView.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import 'package:autocomplete_textfield/autocomplete_textfield.dart';
  2. import 'package:colorize_logger/colorize_logger.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get_it/get_it.dart';
  5. import 'package:ustest/BuildHistoryList.dart';
  6. import 'Services/BuildService.dart';
  7. class BuildView extends StatefulWidget {
  8. @override
  9. State<StatefulWidget> createState() {
  10. // TODO: implement createState
  11. return _BuildView();
  12. }
  13. }
  14. class _BuildView extends State<BuildView> {
  15. final platforms = ["Windows", "Linux", "IOS"];
  16. String? selectedPlatform;
  17. GlobalKey<AutoCompleteTextFieldState<String>> platformKey =
  18. GlobalKey<AutoCompleteTextFieldState<String>>();
  19. @override
  20. Widget build(BuildContext context) {
  21. Future<List<BuildHistory>> future = fetchBuildHistories();
  22. GlobalKey listKey = GlobalKey();
  23. return Scaffold(
  24. body: Center(
  25. child: Column(
  26. children: [
  27. Row(
  28. children: [
  29. Text(
  30. 'Platform:',
  31. style: TextStyle(backgroundColor: Colors.lightBlueAccent),
  32. textAlign: TextAlign.center,
  33. ),
  34. SizedBox(
  35. width: 136,
  36. child: Expanded(
  37. child: DropdownButtonFormField<String>(
  38. decoration: InputDecoration(
  39. hintText: "Select an platform",
  40. contentPadding: EdgeInsets.all(0.0)),
  41. onChanged: (item) {
  42. setState(() => this.selectedPlatform = item);
  43. },
  44. key: platformKey,
  45. value: selectedPlatform,
  46. items: platforms
  47. .map((e) => DropdownMenuItem<String>(
  48. child: Container(
  49. child: Text(e),
  50. width: 100,
  51. ),
  52. value: e,
  53. ))
  54. .toList(),
  55. ),
  56. )),
  57. TextButton.icon(
  58. style: ButtonStyle(
  59. backgroundColor:
  60. MaterialStateProperty.all(Colors.lightBlueAccent)),
  61. onPressed: () => onBuild(context),
  62. icon: Icon(Icons.rule_rounded),
  63. label: Text(
  64. "Build",
  65. style: TextStyle(color: Colors.white),
  66. )),
  67. ],
  68. ),
  69. Row(
  70. children: [
  71. TextButton.icon(
  72. onPressed: () => setState(() {}),
  73. icon: Icon(Icons.search),
  74. label: Text("Search")),
  75. ],
  76. ),
  77. Expanded(
  78. child: Center(
  79. child: FutureBuilder<List<BuildHistory>>(
  80. key: listKey,
  81. future: future,
  82. builder: (context, snapshot) {
  83. if (snapshot.hasError) {
  84. return const Center(
  85. child: Text('An error has occurred!'),
  86. );
  87. } else if (snapshot.hasData) {
  88. return BuildHistoryList(
  89. token: "accessToken", histories: snapshot.data!);
  90. } else {
  91. return const Center(
  92. child: CircularProgressIndicator(),
  93. );
  94. }
  95. },
  96. ),
  97. )),
  98. ],
  99. ),
  100. ),
  101. );
  102. }
  103. Future<List<BuildHistory>> fetchBuildHistories() async {
  104. try {
  105. var service = GetIt.instance.get<BuildService>();
  106. return List.empty();
  107. } catch (ex) {
  108. Logger.error('fetchBuildHistories ex:' + ex.toString());
  109. return List.empty();
  110. }
  111. }
  112. void onBuild(context) {
  113. try {
  114. var service = GetIt.instance.get<BuildService>();
  115. service.Run();
  116. } catch (ex) {
  117. Logger.error("onBuild ex:${ex}");
  118. }
  119. }
  120. }