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.

92 lines
2.7KB

  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. appBar: AppBarWidget(
  26. isBack: false,
  27. ),
  28. body: BlocProvider<DeviceBloc>(
  29. create: (context) =>
  30. DeviceBloc(repository: Repository())..add(OpenScreen()),
  31. child: _buildContent()));
  32. }
  33. Widget _buildContent() {
  34. return Column(
  35. crossAxisAlignment: CrossAxisAlignment.start,
  36. children: [
  37. Padding(
  38. padding: const EdgeInsets.all(8.0),
  39. child: Text(
  40. 'Thiết bị',
  41. style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22),
  42. ),
  43. ),
  44. Padding(
  45. padding: const EdgeInsets.all(8.0),
  46. child: Text('Điều khiển thiết bị từ xa',
  47. style: TextStyle(
  48. fontSize: 15,
  49. fontWeight: FontWeight.w200,
  50. color: Colors.black54)),
  51. ),
  52. SearchWidget(searchPressed: (value) {
  53. FocusScope.of(context).requestFocus(FocusNode());
  54. _deviceBloc.add(OnSearch(query: value));
  55. }),
  56. Expanded(
  57. child: BlocBuilder<DeviceBloc, DeviceState>(
  58. cubit: _deviceBloc,
  59. builder: (context, state) {
  60. if (state is DisplayDevice) {
  61. if (state.loading) {
  62. return Container(
  63. child: Center(
  64. child: CircularProgressIndicator(),
  65. ),
  66. );
  67. }
  68. if (state.devices != null) {
  69. return Container(
  70. child: WidgetDeviceList(
  71. devices: state.devices,
  72. deviceBloc: _deviceBloc,
  73. ),
  74. );
  75. }
  76. return Container();
  77. } else {
  78. return Container();
  79. }
  80. },
  81. ))
  82. ],
  83. );
  84. }
  85. }