|
- import 'package:farm_tpf/data/repository/repository.dart';
- import 'package:farm_tpf/presentation/screens/control_device/widget_device_list.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
-
- import 'bloc/device_bloc.dart';
-
- class ControlDeviceScreen extends StatefulWidget {
- @override
- _ControlDeviceScreenState createState() => _ControlDeviceScreenState();
- }
-
- class _ControlDeviceScreenState extends State<ControlDeviceScreen> {
- BuildContext _blocContext;
- @override
- void initState() {
- super.initState();
- }
-
- @override
- Widget build(BuildContext context) {
- _blocContext = context;
- return Scaffold(
- appBar: AppBar(
- title: Text("Điều khiển thiết bị"),
- ),
- body: BlocProvider<DeviceBloc>(
- create: (context) =>
- DeviceBloc(repository: Repository())..add(OpenScreen()),
- child: _buildContent()));
- }
-
- Widget _buildContent() {
- return BlocBuilder<DeviceBloc, DeviceState>(
- builder: (context, state) {
- if (state is DisplayDevice) {
- if (state.loading) {
- return Container(
- child: Center(
- child: CircularProgressIndicator(),
- ),
- );
- }
-
- if (state.devices != null) {
- return Container(
- child: WidgetDeviceList(devices: state.devices),
- );
- }
- return Container();
- } else {
- return Container();
- }
- },
- );
- }
- }
|