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.

59 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. centerTitle: true,
  22. title: Text("Điều khiển thiết bị"),
  23. ),
  24. body: BlocProvider<DeviceBloc>(
  25. create: (context) =>
  26. DeviceBloc(repository: Repository())..add(OpenScreen()),
  27. child: _buildContent()));
  28. }
  29. Widget _buildContent() {
  30. return BlocBuilder<DeviceBloc, DeviceState>(
  31. builder: (context, state) {
  32. if (state is DisplayDevice) {
  33. if (state.loading) {
  34. return Container(
  35. child: Center(
  36. child: CircularProgressIndicator(),
  37. ),
  38. );
  39. }
  40. if (state.devices != null) {
  41. return Container(
  42. child: WidgetDeviceList(devices: state.devices),
  43. );
  44. }
  45. return Container();
  46. } else {
  47. return Container();
  48. }
  49. },
  50. );
  51. }
  52. }