track_page.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_blue/flutter_blue.dart';
  3. import 'package:flutter_tracker/utils/app_util.dart';
  4. import 'package:flutter_tracker/views/contact_card.dart';
  5. import 'bluetooth_off_page.dart';
  6. /// Description:
  7. /// Time : 2021年12月03日 Friday
  8. /// Author : liuyuqi.gov@msncn
  9. class TrackPage extends StatefulWidget {
  10. const TrackPage({Key key}) : super(key: key);
  11. @override
  12. _TrackPageState createState() => _TrackPageState();
  13. }
  14. class _TrackPageState extends State<TrackPage> {
  15. String testText = '';
  16. List<dynamic> contactTraces = [];
  17. List<dynamic> contactTimes = [];
  18. List<dynamic> contactLocations = [];
  19. @override
  20. Widget build(BuildContext context) {
  21. return StreamBuilder<BluetoothState>(
  22. stream: FlutterBlue.instance.state,
  23. initialData: BluetoothState.unknown,
  24. builder: (c, snapshot) {
  25. final state = snapshot.data;
  26. if (state == BluetoothState.on) {
  27. return buildContent();
  28. }
  29. return BluetoothOffPage(state: state);
  30. });
  31. }
  32. Column buildContent() {
  33. return Column(
  34. children: <Widget>[
  35. Expanded(
  36. child: Padding(
  37. padding: const EdgeInsets.only(
  38. left: 25.0,
  39. right: 25.0,
  40. bottom: 10.0,
  41. top: 30.0,
  42. ),
  43. child: Container(
  44. height: 50.0,
  45. width: double.infinity,
  46. decoration: BoxDecoration(
  47. color: Colors.deepPurple[500],
  48. borderRadius: BorderRadius.circular(20.0),
  49. boxShadow: const [
  50. BoxShadow(
  51. color: Colors.black,
  52. blurRadius: 4.0,
  53. spreadRadius: 0.0,
  54. offset: Offset(2.0, 2.0), // shadow direction: bottom right
  55. )
  56. ],
  57. ),
  58. child: Row(
  59. children: const <Widget>[
  60. Expanded(
  61. child: Image(
  62. image: AssetImage('assets/images/corona.png'),
  63. ),
  64. ),
  65. Expanded(
  66. flex: 2,
  67. child: Text(
  68. '附近用户',
  69. textAlign: TextAlign.left,
  70. style: TextStyle(
  71. fontSize: 21.0,
  72. color: Colors.white,
  73. fontWeight: FontWeight.w500,
  74. ),
  75. ),
  76. )
  77. ],
  78. ),
  79. ),
  80. ),
  81. ),
  82. Padding(
  83. padding: EdgeInsets.only(bottom: 200.0),
  84. child: RaisedButton(
  85. shape: RoundedRectangleBorder(
  86. borderRadius: BorderRadius.circular(20.0)),
  87. elevation: 5.0,
  88. color: Colors.deepPurple[400],
  89. onPressed: () async {
  90. startTrack();
  91. },
  92. child: const Text(
  93. '开始追踪',
  94. style: TextStyle(
  95. fontSize: 20.0,
  96. fontWeight: FontWeight.bold,
  97. color: Colors.white,
  98. ),
  99. ),
  100. ),
  101. ),
  102. Expanded(
  103. flex: 2,
  104. child: Padding(
  105. padding: const EdgeInsets.symmetric(horizontal: 25.0),
  106. child: ListView.builder(
  107. itemBuilder: (context, index) {
  108. return ContactCard(
  109. imagePath: 'assets/images/head.jpg',
  110. email: contactTraces[index],
  111. infection: 'Not-Infected',
  112. contactUsername: contactTraces[index],
  113. contactTime: contactTimes[index],
  114. contactLocation: contactLocations[index],
  115. );
  116. },
  117. itemCount: contactTraces.length,
  118. ),
  119. ),
  120. ),
  121. ],
  122. );
  123. }
  124. void startTrack() async {
  125. // try {
  126. // bool a = await Nearby().startAdvertising(
  127. // loggedInUser.email,
  128. // strategy,
  129. // onConnectionInitiated: null,
  130. // onConnectionResult: (id, status) {
  131. // print(status);
  132. // },
  133. // onDisconnected: (id) {
  134. // print('Disconnected $id');
  135. // },
  136. // );
  137. //
  138. // print('ADVERTISING ${a.toString()}');
  139. // } catch (e) {
  140. // print(e);
  141. // }
  142. discovery();
  143. AppUtil.buildToast("正在搜索附近的人...");
  144. AppUtil.buildToast("追踪用户状态中...");
  145. }
  146. void discovery() {}
  147. }