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.

58 lines
1.5KB

  1. import 'package:farm_tpf/data/repository/repository.dart';
  2. import 'package:farm_tpf/presentation/screens/control_device/widget_device_list.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_bloc/flutter_bloc.dart';
  5. import 'bloc/device_bloc.dart';
  6. class ControlDeviceScreen extends StatefulWidget {
  7. @override
  8. _ControlDeviceScreenState createState() => _ControlDeviceScreenState();
  9. }
  10. class _ControlDeviceScreenState extends State<ControlDeviceScreen> {
  11. BuildContext _blocContext;
  12. @override
  13. void initState() {
  14. super.initState();
  15. }
  16. @override
  17. Widget build(BuildContext context) {
  18. _blocContext = context;
  19. return Scaffold(
  20. appBar: AppBar(
  21. title: Text("Điều khiển thiết bị"),
  22. ),
  23. body: BlocProvider<DeviceBloc>(
  24. create: (context) =>
  25. DeviceBloc(repository: Repository())..add(OpenScreen()),
  26. child: _buildContent()));
  27. }
  28. Widget _buildContent() {
  29. return BlocBuilder<DeviceBloc, DeviceState>(
  30. builder: (context, state) {
  31. if (state is DisplayDevice) {
  32. if (state.loading) {
  33. return Container(
  34. child: Center(
  35. child: CircularProgressIndicator(),
  36. ),
  37. );
  38. }
  39. if (state.devices != null) {
  40. return Container(
  41. child: WidgetDeviceList(devices: state.devices),
  42. );
  43. }
  44. return Container();
  45. } else {
  46. return Container();
  47. }
  48. },
  49. );
  50. }
  51. }