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