You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.9KB

  1. import 'package:farm_tpf/data/repository/repository.dart';
  2. import 'package:farm_tpf/presentation/custom_widgets/app_bar_widget.dart';
  3. import 'package:farm_tpf/presentation/custom_widgets/widget_search.dart';
  4. import 'package:farm_tpf/presentation/screens/control_device/widget_device_list.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:flutter_bloc/flutter_bloc.dart';
  7. import 'bloc/device_bloc.dart';
  8. class ControlDeviceScreen extends StatefulWidget {
  9. @override
  10. _ControlDeviceScreenState createState() => _ControlDeviceScreenState();
  11. }
  12. class _ControlDeviceScreenState extends State<ControlDeviceScreen> {
  13. BuildContext? _blocContext;
  14. DeviceBloc _deviceBloc = DeviceBloc(repository: Repository());
  15. @override
  16. void initState() {
  17. super.initState();
  18. _deviceBloc.add(OpenScreen());
  19. }
  20. @override
  21. Widget build(BuildContext context) {
  22. _blocContext = context;
  23. return Scaffold(
  24. backgroundColor: Colors.white,
  25. body: BlocProvider<DeviceBloc>(
  26. create: (context) => DeviceBloc(repository: Repository())..add(OpenScreen()),
  27. child: _buildContent(),
  28. ),
  29. );
  30. }
  31. Widget _buildContent() {
  32. return SafeArea(
  33. child: Column(
  34. crossAxisAlignment: CrossAxisAlignment.start,
  35. children: [
  36. SizedBox(
  37. height: 8,
  38. ),
  39. Padding(
  40. padding: const EdgeInsets.all(8.0),
  41. child: Text(
  42. 'Thiết bị',
  43. style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22),
  44. ),
  45. ),
  46. Padding(
  47. padding: const EdgeInsets.all(8.0),
  48. child: Text('Điều khiển thiết bị từ xa', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200, color: Colors.black54)),
  49. ),
  50. SearchWidget(searchPressed: (value) {
  51. FocusScope.of(context).requestFocus(FocusNode());
  52. _deviceBloc.add(OnSearch(query: value));
  53. }),
  54. Expanded(
  55. child: BlocBuilder<DeviceBloc, DeviceState>(
  56. bloc: _deviceBloc,
  57. builder: (context, state) {
  58. print(state.toString());
  59. if (state is DisplayDevice) {
  60. // if (state.loading ?? false) {
  61. // print('loading');
  62. // return Container(
  63. // child: Center(
  64. // child: CircularProgressIndicator(),
  65. // ),
  66. // );
  67. // }
  68. if (state.devices != null) {
  69. print('devices');
  70. return Container(
  71. child: WidgetDeviceList(
  72. devices: state.devices ?? [],
  73. deviceBloc: _deviceBloc,
  74. ),
  75. );
  76. }
  77. return Container();
  78. } else {
  79. return Container();
  80. }
  81. },
  82. ))
  83. ],
  84. ),
  85. );
  86. }
  87. }