mirror of
https://bitbucket.org/myhomie/myhomie_app.git
synced 2025-12-06 17:11:19 +00:00
131 lines
5.7 KiB
Dart
131 lines
5.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:mycore_api/api.dart';
|
|
import 'package:myhomie_app/Components/loading_common.dart';
|
|
import 'package:myhomie_app/Models/homieContext.dart';
|
|
import 'package:myhomie_app/Screens/Main/Automations/automationDetailPage.dart';
|
|
import 'package:myhomie_app/app_context.dart';
|
|
import 'package:myhomie_app/constants.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class AutomationsScreen extends StatefulWidget {
|
|
AutomationsScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_AutomationsScreenState createState() => _AutomationsScreenState();
|
|
}
|
|
|
|
class _AutomationsScreenState extends State<AutomationsScreen> {
|
|
bool isLoading = true;
|
|
List<AutomationDTO>? allAutomations;
|
|
|
|
@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();
|
|
|
|
return SingleChildScrollView(
|
|
child: Container(
|
|
height: size.height * 0.9,
|
|
child: FutureBuilder(
|
|
future: homieAppContext.clientAPI.automationApi!.automationGetAll(homieAppContext.homeId!),
|
|
builder: (context, AsyncSnapshot<List<AutomationDTO>?> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
allAutomations = snapshot.data;
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: RefreshIndicator(
|
|
color: Theme.of(context).primaryColor,
|
|
displacement: 20,
|
|
onRefresh: () async {
|
|
print("TODO refresh");
|
|
setState(() {});
|
|
return Future(() => null);
|
|
//await Message.getMessages(this.messages, appContext, true, true);
|
|
},
|
|
child: ListView.builder(
|
|
shrinkWrap: true,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: InkWell(
|
|
onTap: () {
|
|
debugPrint(allAutomations![index].toString());
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => AutomationDetailPage(
|
|
automationDTO: allAutomations![index],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
child: Container(
|
|
height: size.height * 0.1,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
shape: BoxShape.rectangle,
|
|
borderRadius: BorderRadius.circular(20.0),
|
|
border: Border.all(
|
|
color: kBackgroundSecondGrey.withOpacity(0.35),
|
|
width: 0.2,
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: kMainColor.withOpacity(0.35),
|
|
//spreadRadius: 0.15,
|
|
blurRadius: 5,
|
|
offset: const Offset(0, 10), // changes position of shadow
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.max,
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Text(allAutomations![index].name!),
|
|
Switch(
|
|
// thumb color (round icon)
|
|
activeColor: kMainColor,
|
|
activeTrackColor: Colors.grey.shade400,
|
|
inactiveThumbColor: Colors.blueGrey.shade600,
|
|
inactiveTrackColor: Colors.grey.shade400,
|
|
splashRadius: 50.0,
|
|
// boolean variable value
|
|
value: allAutomations![index].active!,
|
|
// changes the state of the switch
|
|
onChanged: (bool value) {
|
|
|
|
/*setState(() {
|
|
allAutomations![index].active = value;
|
|
// TODO save
|
|
});*/
|
|
}
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
itemCount: allAutomations!.length
|
|
),
|
|
),
|
|
);
|
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
|
print('ConnectionState.none');
|
|
return Text("No data");
|
|
} else {
|
|
return Container(height: size.height * 0.2, child: LoadingCommon());
|
|
}
|
|
}
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |