mirror of
https://bitbucket.org/myhomie/myhomie_app.git
synced 2025-12-06 00:51:19 +00:00
215 lines
8.4 KiB
Dart
215 lines
8.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mycoreapi/api.dart';
|
|
import 'package:myhomie_app/Components/loading.dart';
|
|
import 'package:myhomie_app/Models/homieContext.dart';
|
|
import 'package:myhomie_app/app_context.dart';
|
|
import 'package:myhomie_app/constants.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
HomeScreen({Key key}) : super(key: key);
|
|
|
|
@override
|
|
_HomeScreenState createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
bool isLoading = true;
|
|
//List<Message> messages;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Size size = MediaQuery.of(context).size;
|
|
final appContext = Provider.of<AppContext>(context);
|
|
HomieAppContext homieAppContext = appContext.getContext();
|
|
|
|
print(homieAppContext.homeId);
|
|
print(homieAppContext.clientAPI.roomApi);
|
|
// TODO
|
|
/*if(appContext.getContext().feed != null) {
|
|
return interfaceElements();
|
|
} else {*/
|
|
return FutureBuilder(
|
|
future: homieAppContext.clientAPI.roomApi.roomGetAllWithMainDetails(homieAppContext.homeId),
|
|
builder: (context, AsyncSnapshot<List<RoomMainDetailDTO>> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
print("connectionState done");
|
|
print(snapshot);
|
|
if(snapshot.data != null) {
|
|
return interfaceElements(snapshot.data);
|
|
} else {
|
|
return Text("No data - or error");
|
|
}
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
print('ConnectionState.none');
|
|
return Text("No data");
|
|
} else {
|
|
return Container(height: size.height * 0.2, child: Loading());
|
|
}
|
|
}
|
|
);
|
|
//}
|
|
}
|
|
|
|
interfaceElements(List<RoomMainDetailDTO> roomsMaindetails) {
|
|
Size size = MediaQuery.of(context).size;
|
|
final appContext = Provider.of<AppContext>(context);
|
|
HomieAppContext homieAppContext = appContext.getContext();
|
|
|
|
print(roomsMaindetails.length);
|
|
print(roomsMaindetails[0].door);
|
|
print(roomsMaindetails[0].isDoor);
|
|
|
|
return RefreshIndicator(
|
|
color: Theme.of(context).primaryColor,
|
|
displacement: 20,
|
|
onRefresh: () async {
|
|
print("onRefresh");
|
|
await homieAppContext.clientAPI.roomApi.roomGetAllWithMainDetails(homieAppContext.homeId);
|
|
},
|
|
child: Container(
|
|
height: size.height * 0.8,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
GridView.builder(
|
|
shrinkWrap: true,
|
|
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2, childAspectRatio: 1),
|
|
itemCount: roomsMaindetails.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return InkWell(
|
|
onTap: () {
|
|
setState(() {
|
|
//selectedSection = menuDTO.sections[index];
|
|
print("Hero to room detail");
|
|
});
|
|
},
|
|
child: Container(
|
|
decoration: boxDecorationRoom(roomsMaindetails[index], false),
|
|
padding: const EdgeInsets.all(5),
|
|
margin: EdgeInsets.symmetric(vertical: 8, horizontal: 8),
|
|
child: Stack(
|
|
children: [
|
|
Column(
|
|
children: [
|
|
Align(
|
|
alignment: Alignment.bottomLeft,
|
|
child: Text(
|
|
roomsMaindetails[index].name,
|
|
style: new TextStyle(fontSize: kDetailSize, color: kBackgroundSecondGrey),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
if(roomsMaindetails[index].isTemperature)
|
|
Positioned(
|
|
bottom: 10,
|
|
left: 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.thermostat,
|
|
size: 20,
|
|
color: kMainColor,
|
|
),
|
|
Text(
|
|
roomsMaindetails[index].temperature,
|
|
style: new TextStyle(fontSize: kDescriptionDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomsMaindetails[index].isHumidity)
|
|
Positioned(
|
|
bottom: 10,
|
|
left: roomsMaindetails[index].isTemperature ? 55 : 0,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.water,
|
|
size: 20,
|
|
color: kMainColor,
|
|
),
|
|
Text(
|
|
roomsMaindetails[index].humidity,
|
|
style: new TextStyle(fontSize: kDescriptionDetailSize, color: kBackgroundSecondGrey),
|
|
maxLines: 1,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomsMaindetails[index].isDoor)
|
|
Positioned(
|
|
bottom: 10,
|
|
right: 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.motion_photos_on_rounded,
|
|
size: 20,
|
|
color: !roomsMaindetails[index].door ? kMainColor : kBackgroundSecondGrey,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
|
|
if(roomsMaindetails[index].isMotion)
|
|
Positioned(
|
|
bottom: 10,
|
|
right: roomsMaindetails[index].isDoor ? 20 : 5,
|
|
child: Row(
|
|
children: [
|
|
Icon(
|
|
Icons.directions_walk,
|
|
size: 20,
|
|
color: roomsMaindetails[index].motion ? kMainColor : kBackgroundSecondGrey,
|
|
),
|
|
],
|
|
)
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
boxDecorationRoom(RoomMainDetailDTO roomMainDetailDTO, bool isSelected) {
|
|
return BoxDecoration(
|
|
color: kBackgroundLight,
|
|
shape: BoxShape.rectangle,
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
/*image: roomMainDetailDTO.imageSource != null ? new DecorationImage(
|
|
fit: BoxFit.contain,
|
|
colorFilter: !isSelected? new ColorFilter.mode(Colors.black.withOpacity(0.5), BlendMode.dstATop) : null,
|
|
image: new NetworkImage(
|
|
section.imageSource,
|
|
),
|
|
): null,*/
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kBackgroundSecondGrey,
|
|
spreadRadius: 0.5,
|
|
blurRadius: 6,
|
|
offset: Offset(0, 1.5), // changes position of shadow
|
|
),
|
|
],
|
|
);
|
|
} |