This commit is contained in:
Aditya Pulipaka
2025-07-10 18:52:04 -05:00
commit e0a41761ec
166 changed files with 8444 additions and 0 deletions

View File

@@ -0,0 +1,406 @@
import 'dart:convert';
import 'package:blind_master/BlindMasterResources/error_snackbar.dart';
import 'package:blind_master/BlindMasterResources/secure_transmissions.dart';
import 'package:blind_master/BlindMasterResources/text_inputs.dart';
import 'package:blind_master/BlindMasterScreens/individualControl/peripheral_screen.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class DeviceScreen extends StatefulWidget {
final int deviceId;
const DeviceScreen({super.key, required this.deviceId});
@override
State<DeviceScreen> createState() => _DeviceScreenState();
}
class _DeviceScreenState extends State<DeviceScreen> {
bool enabled = false;
final _newPeripheralNameController = TextEditingController();
final _hubRenameController = TextEditingController();
List<Map<String, dynamic>> peripherals = [];
List occports = [];
Widget? peripheralList;
String deviceName = "...";
@override
void initState() {
super.initState();
initAll();
}
Future initAll() async {
await getDeviceName();
await populatePeripherals();
}
Future getDeviceName() async {
try {
final payload = {
"deviceId": widget.deviceId
};
final response = await secureGet('device_name', queryParameters: payload);
if (response == null) throw Exception("no response!");
if (response.statusCode == 200) {
final body = json.decode(response.body) as Map<String, dynamic>;
setState(() {
deviceName = body['device_name'];
});
}
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
Future populatePeripherals() async {
setState(() {
peripheralList = null;
});
try {
final payload = {
"deviceId": widget.deviceId
};
final response = await secureGet('peripheral_list', queryParameters: payload);
if (response == null) throw Exception("no response!");
if (response.statusCode == 200) {
final body = json.decode(response.body) as Map<String, dynamic>;
final names = body['peripheral_names'] as List;
final ids = body['peripheral_ids'] as List;
occports = body['port_nums'] as List;
peripherals = List.generate(names.length, (i) => {
'id': ids[i],
'name': names[i],
'port': occports[i]
});
peripherals.sort((a, b) => (a['port'] as int).compareTo(b['port'] as int));
enabled = peripherals.length < 4;
}
setState(() {
peripheralList = RefreshIndicator(
onRefresh: populatePeripherals,
child: peripherals.isEmpty ? SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: SizedBox(
height: MediaQuery.of(context).size.height * 0.6,
child: const Center(
child: Text(
"No peripherals found...\nAdd one using the '+' button",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
),
),
) : ListView.builder(
itemCount: peripherals.length,
itemBuilder: (context, i) {
final peripheral = peripherals[i];
return Dismissible(
key: Key(peripheral['id'].toString()),
direction: DismissDirection.endToStart,
background: Container(
color: Colors.red,
alignment: Alignment.centerRight,
padding: const EdgeInsets.symmetric(horizontal: 20),
child: const Icon(Icons.delete, color: Colors.white),
),
confirmDismiss: (direction) async {
// Ask for confirmation (optional)
return await showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Delete Peripheral'),
content: const Text('Are you sure you want to delete this peripheral?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Delete'),
),
],
),
);
},
onDismissed: (direction) => deletePeripheral(peripheral['id'], i),
child: Card(
child: ListTile(
leading: const Icon(Icons.blinds),
title: Text(peripheral['name']),
subtitle: Text("Port #${peripheral['port']}"),
trailing: const Icon(Icons.arrow_forward_ios_rounded),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PeripheralScreen(peripheralId: peripheral['id'],
peripheralNum: peripheral['port'], deviceId: widget.deviceId,),
),
).then((_) { populatePeripherals(); });
},
),
),
);
},
),
);
});
return Future.delayed(Duration(milliseconds: 500));
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
Future deletePeripheral(int id, int i) async {
setState(() {
peripherals.removeAt(i);
peripheralList = null;
});
final payload = {
'periphId': id,
};
try {
final response = await securePost(payload, 'delete_peripheral');
if (response == null) return;
if (response.statusCode != 204) {
if (response.statusCode == 404) {throw Exception('Device Not Found');}
else if (response.statusCode == 500) {throw Exception('Server Error');}
}
if (mounted){
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text(
'Deleted',
textAlign: TextAlign.center,
)
),
);
}
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
populatePeripherals();
}
void addPeripheral() {
var freePorts = <int>{};
for (int i = 1; i < 5; i++) {
freePorts.add(i);
}
freePorts = freePorts.difference(occports.toSet());
int? port = freePorts.firstOrNull;
showDialog(
context: context,
builder: (BuildContext dialogContext) { // Use dialogContext for navigation within the dialog
return AlertDialog(
title: Text(
'New Peripheral',
style: GoogleFonts.aBeeZee(),
),
content: Column(
mainAxisSize: MainAxisSize.min, // Keep column compact
children: <Widget>[
TextFormField(
controller: _newPeripheralNameController,
decoration: const InputDecoration(
labelText: 'Peripheral Name',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 20),
DropdownButtonFormField<int>(
value: port,
decoration: const InputDecoration(
labelText: 'Hub Port',
border: OutlineInputBorder(),
),
items: freePorts.map((int number) {
return DropdownMenuItem<int>(
value: number,
child: Text('$number'),
);
}).toList(),
onChanged: (int? newValue) {
setState(() {
port = newValue;
});
},
),
],
),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
Navigator.of(dialogContext).pop();
},
child: const Text(
"Cancel",
style: TextStyle(
color: Colors.red
),
)
),
ElevatedButton(
onPressed: () {
uploadPeriphData(_newPeripheralNameController.text, port);
Navigator.of(dialogContext).pop();
},
child: const Text("Add"),
),
]
)
],
);
}
);
}
Future uploadPeriphData(String name, int? port) async {
try {
if (name.isEmpty || port == null) {
throw Exception("Name and Port Required");
}
final payload = {
'device_id': widget.deviceId,
'port_num': port,
'peripheral_name': name
};
final response = await securePost(payload, 'add_peripheral');
if (response == null) throw Exception("Auth Error");
if (response.statusCode != 201) {
if (response.statusCode == 409) throw Exception("Choose a unique name!");
throw Exception("Server Error");
}
populatePeripherals();
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
void rename() {
showDialog(
context: context,
builder: (BuildContext dialogContext) {
return AlertDialog(
title: Text(
"Rename Hub",
style: GoogleFonts.aBeeZee(),
),
content: BlindMasterMainInput("New Hub Name", controller: _hubRenameController,),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
Navigator.of(dialogContext).pop();
},
child: const Text(
"Cancel",
style: TextStyle(
color: Colors.red
),
)
),
ElevatedButton(
onPressed: () {
updateHubName(_hubRenameController.text, widget.deviceId);
Navigator.of(dialogContext).pop();
},
child: const Text("Confirm")
)
],
)
],
);
}
);
}
Future updateHubName(String name, int id) async {
try {
if (name.isEmpty) throw Exception("New name cannot be empty!");
final payload = {
'deviceId': id,
'newName': name,
};
final response = await securePost(payload, 'rename_device');
if (response == null) throw Exception("Auth Error");
if (response.statusCode != 204) {
if (response.statusCode == 409) throw Exception("Choose a unique name!");
throw Exception("Server Error");
}
getDeviceName();
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
deviceName,
style: GoogleFonts.aBeeZee(),
),
backgroundColor: Theme.of(context).primaryColorLight,
foregroundColor: Colors.white,
),
body: peripheralList ?? SizedBox(
height: MediaQuery.of(context).size.height * 0.8,
child: Center(
child: CircularProgressIndicator(
color: Theme.of(context).primaryColorLight,
),
)
),
floatingActionButton: Container(
padding: EdgeInsets.all(25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
FloatingActionButton(
backgroundColor: Theme.of(context).primaryColorDark,
foregroundColor: Theme.of(context).highlightColor,
heroTag: "rename",
onPressed: rename,
tooltip: "Rename Hub",
child: Icon(Icons.drive_file_rename_outline_sharp),
),
FloatingActionButton(
backgroundColor: enabled
? Theme.of(context).primaryColorDark
: Theme.of(context).disabledColor,
foregroundColor: Theme.of(context).highlightColor,
heroTag: "add",
onPressed: enabled ? addPeripheral : null,
tooltip: "Add Peripheral",
child: Icon(Icons.add),
)
],
)
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}

View File

@@ -0,0 +1,175 @@
import 'dart:convert';
import 'package:blind_master/BlindMasterResources/error_snackbar.dart';
import 'package:blind_master/BlindMasterResources/secure_transmissions.dart';
import 'package:blind_master/BlindMasterScreens/addingDevices/add_device.dart';
import 'package:blind_master/BlindMasterScreens/individualControl/device_screen.dart';
import 'package:flutter/material.dart';
class DevicesMenu extends StatefulWidget {
const DevicesMenu({super.key});
@override
State<DevicesMenu> createState() => _DevicesMenuState();
}
class _DevicesMenuState extends State<DevicesMenu> {
List<Map<String, dynamic>> devices = [];
Widget? deviceList;
@override
void initState() {
super.initState();
getDevices();
}
Future getDevices() async {
try{
final response = await secureGet('device_list');
if (response == null) throw Exception("no response!");
if (response.statusCode == 200) {
final body = json.decode(response.body) as Map<String, dynamic>;
final names = body['devices'] as List;
final ids = body['device_ids'] as List;
devices = List.generate(names.length, (i) => {
'id': ids[i],
'name': names[i],
});
}
} catch(e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
errorSnackbar(e)
);
}
setState(() {
deviceList = RefreshIndicator(
onRefresh: getDevices,
child: devices.isEmpty
? SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: SizedBox(
height: MediaQuery.of(context).size.height * 0.6,
child: const Center(
child: Text(
"No hubs found...\nAdd one using the '+' button",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
),
),
)
: ListView.builder(
itemCount: devices.length,
itemBuilder: (context, i) {
final device = devices[i];
return Dismissible(
key: Key(device['id'].toString()),
direction: DismissDirection.endToStart,
background: Container(
color: Colors.red,
alignment: Alignment.centerRight,
padding: const EdgeInsets.symmetric(horizontal: 20),
child: const Icon(Icons.delete, color: Colors.white),
),
confirmDismiss: (direction) async {
// Ask for confirmation (optional)
return await showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Delete Hub'),
content: const Text('Are you sure you want to delete this hub?'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('Delete'),
),
],
),
);
},
onDismissed: (direction) {
// Actually delete the device
deleteDevice(device['id'], i);
},
child: Card(
child: ListTile(
leading: const Icon(Icons.blinds),
title: Text(device['name']),
trailing: const Icon(Icons.arrow_forward_ios_rounded),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DeviceScreen(deviceId: device['id']),
),
).then((_) { getDevices(); });
},
),
),
);
},
),
);
});
return Future.delayed(Duration(milliseconds: 500));
}
Future deleteDevice(int id, int i) async {
setState(() {
devices.removeAt(i);
deviceList = null;
});
print("deleting");
final payload = {
'deviceId': id,
};
try {
final response = await securePost(payload, 'delete_device');
if (response == null) return;
if (response.statusCode != 204) {
if (response.statusCode == 404) {throw Exception('Device Not Found');}
else if (response.statusCode == 500) {throw Exception('Server Error');}
}
if (mounted){
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Deleted',
textAlign: TextAlign.center,
)
),
);
}
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
getDevices();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: deviceList ?? const Center(child: CircularProgressIndicator()),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => AddDevice()),
);
},
foregroundColor: Theme.of(context).highlightColor,
backgroundColor: Theme.of(context).primaryColorDark,
child: Icon(Icons.add),
),
);
}
}

View File

@@ -0,0 +1,524 @@
import 'dart:convert';
import 'package:blind_master/BlindMasterResources/blindmaster_progress_indicator.dart';
import 'package:blind_master/BlindMasterResources/error_snackbar.dart';
import 'package:blind_master/BlindMasterResources/secure_transmissions.dart';
import 'package:blind_master/BlindMasterResources/text_inputs.dart';
import 'package:blind_master/BlindMasterScreens/schedules_screen.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:socket_io_client/socket_io_client.dart' as IO;
class PeripheralScreen extends StatefulWidget {
const PeripheralScreen({super.key, required this.peripheralId, required this.deviceId, required this.peripheralNum});
final int peripheralId;
final int peripheralNum;
final int deviceId;
@override
State<PeripheralScreen> createState() => _PeripheralScreenState();
}
class _PeripheralScreenState extends State<PeripheralScreen> {
IO.Socket? socket;
String imagePath = "";
String peripheralName = "...";
bool loaded = false;
bool calibrated = false;
bool calibrating = false;
double _blindPosition = 5.0;
DateTime? lastSet;
String lastSetMessage = "";
final _peripheralRenameController = TextEditingController();
void getImage() {
final hour = DateTime.now().hour;
if (hour >= 5 && hour < 10) {
imagePath = 'assets/images/MorningSill.png';
} else if (hour >= 10 && hour < 18) {
imagePath = 'assets/images/NoonSill.png';
} else if (hour >= 18 && hour < 22) {
imagePath = 'assets/images/EveningSill.png';
} else {
imagePath = 'assets/images/NightSill.png';
}
}
@override
void initState() {
super.initState();
initAll();
initSocket();
}
@override
void dispose() {
socket?.disconnect();
socket?.dispose();
super.dispose();
}
Future<void> initSocket() async {
try {
socket = await connectSocket();
if (socket == null) throw Exception("Unsuccessful socket connection");
socket?.on("success", (_) {
socket?.on("posUpdates", (list) {
for (var update in list) {
if (update is Map<String, dynamic>) {
if (update['periphID'] == widget.peripheralId) {
if (!mounted) return;
setState(() {
_blindPosition = (update['pos'] as int).toDouble();
});
}
}
}
});
socket?.on("calib", (periphData) {
if (periphData is Map<String, dynamic>) {
if (periphData['periphID'] == widget.peripheralId) {
if (!mounted) return;
setState(() {
calibrating = true;
calibrated = false;
});
}
}
});
socket?.on("calib_done", (periphData) {
if (periphData is Map<String, dynamic>) {
if (periphData['periphID'] == widget.peripheralId) {
if (!mounted) return;
setState(() {
calibrating = false;
calibrated = true;
});
}
}
});
});
} catch (e) {
if (mounted) ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
Future<void> calibrate() async {
try {
final payload = {
'periphId': widget.peripheralId
};
final response = await securePost(payload, 'calib');
if (response == null) throw Exception("auth error");
if (response.statusCode != 202) throw Exception("Server Error");
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
Future<void> cancelCalib() async {
try {
final payload = {
'periphId': widget.peripheralId
};
final response = await securePost(payload, 'cancel_calib');
if (response == null) throw Exception("auth error");
if (response.statusCode != 202) throw Exception("Server Error");
setState(() {
calibrated = false;
calibrating = false;
});
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
Future<void> getName() async {
try {
final payload = {
'periphId': widget.peripheralId
};
final response = await secureGet('peripheral_name', queryParameters: payload);
if (response == null) throw Exception("auth error");
if (response.statusCode != 200) throw Exception("Server Error");
final body = json.decode(response.body);
setState(() => peripheralName = body['name']);
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
Future loop() async{
try {
final payload = {
'periphId': widget.peripheralId
};
final response = await secureGet('peripheral_status', queryParameters: payload);
if (response == null) throw Exception("auth error");
if (response.statusCode != 200) {
if (response.statusCode == 404) throw Exception("Device Not Found");
throw Exception("Server Error");
}
final body = json.decode(response.body) as Map<String, dynamic>;
if (!body['await_calib']){
if (!body['calibrated']) {
calibrated = false;
calibrating = false;
}
else {
getImage();
final nowUtc = DateTime.now().toUtc();
final lastSetUtc = DateTime.parse(body['last_set']);
final Duration difference = nowUtc.difference(lastSetUtc);
if (!lastSetUtc.isUtc) throw Exception("Why isn't the server giving UTC?");
final diffDays = difference.inDays > 0;
final diffHours = difference.inHours > 0;
final diffMins = difference.inMinutes > 0;
lastSetMessage = "Last set ${diffDays ? '${difference.inDays.toString()} days' : diffHours ? '${difference.inHours.toString()} hours' : diffMins ? '${difference.inMinutes.toString()} minutes' : '${difference.inSeconds.toString()} seconds'} ago";
_blindPosition = (body['last_pos'] as int).toDouble();
calibrated = true;
calibrating = false;
}
}
else {
calibrating = true;
}
setState(() {loaded = true;});
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
Future initAll() async{
getName();
loop();
}
void rename() {
showDialog(
context: context,
builder: (BuildContext dialogContext) {
return AlertDialog(
title: Text(
"Rename Peripheral",
style: GoogleFonts.aBeeZee(),
),
content: BlindMasterMainInput("New Peripheral Name", controller: _peripheralRenameController,),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
Navigator.of(dialogContext).pop();
},
child: const Text(
"Cancel",
style: TextStyle(
color: Colors.red
),
)
),
ElevatedButton(
onPressed: () {
updatePeriphName(_peripheralRenameController.text, widget.peripheralId);
Navigator.of(dialogContext).pop();
},
child: const Text("Confirm")
)
],
)
],
);
}
);
}
Future updatePeriphName(String name, int id) async {
try {
if (name.isEmpty) throw Exception("New name cannot be empty!");
final payload = {
'periphId': id,
'newName': name,
};
final response = await securePost(payload, 'rename_peripheral');
if (response == null) throw Exception("Auth Error");
if (response.statusCode != 204) {
if (response.statusCode == 409) throw Exception("Choose a unique name!");
throw Exception("Server Error");
}
getName();
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
void recalibrate() {
showDialog(
context: context,
builder: (BuildContext dialogContext) {
return AlertDialog(
title: Text(
"Recalibrate Peripheral",
style: GoogleFonts.aBeeZee(),
),
content: const Text(
"This will take under a minute",
textAlign: TextAlign.center,
),
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
ElevatedButton(
onPressed: () {
Navigator.of(dialogContext).pop();
},
child: const Text(
"Cancel",
style: TextStyle(
color: Colors.red
),
)
),
ElevatedButton(
onPressed: () {
calibrate();
Navigator.of(dialogContext).pop();
},
child: const Text("Confirm")
)
],
)
],
);
}
);
}
Future updateBlindPosition() async {
try {
final payload = {
'periphId': widget.peripheralId,
'periphNum': widget.peripheralNum,
'deviceId': widget.deviceId,
'newPos': _blindPosition.toInt(),
};
final response = await securePost(payload, 'manual_position_update');
if (response == null) throw Exception("Auth Error");
if (response.statusCode != 202) {
throw Exception("Server Error");
}
} catch (e) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(errorSnackbar(e));
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
peripheralName,
style: GoogleFonts.aBeeZee(),
),
backgroundColor: Theme.of(context).primaryColorLight,
foregroundColor: Colors.white,
),
body: loaded
? (calibrating
? RefreshIndicator(
onRefresh: initAll,
child: SingleChildScrollView(
physics: const AlwaysScrollableScrollPhysics(),
child: SizedBox(
height: MediaQuery.of(context).size.height * 0.8,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(20),
child: Text(
"Calibrating... Check again soon."
),
),
ElevatedButton(
onPressed: cancelCalib,
child: const Text(
"Cancel",
style: TextStyle(
color: Colors.red
),
)
)
]
)
)
)
)
)
: (calibrated
? Column(
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.5,
child: Container(
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: MediaQuery.of(context).size.width * 0.15,
),
Stack(
children: [
// Background image
Align(
alignment: Alignment.center,
child: Image.asset(
imagePath,
// fit: BoxFit.cover,
width: MediaQuery.of(context).size.width * 0.7,
),
),
Align(
alignment: Alignment.center,
child: Container(
margin: EdgeInsets.only(top: MediaQuery.of(context).size.width * 0.05),
height: MediaQuery.of(context).size.width * 0.68,
width: MediaQuery.of(context).size.width * 0.7,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: List.generate(10, (index) {
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
height: _blindPosition < 5 ?
5.4 * (5 - _blindPosition)
: 5.4 * (_blindPosition - 5),
width: MediaQuery.of(context).size.width * 0.65, // example
color: const Color.fromARGB(255, 121, 85, 72),
);
}),
),
)
)
],
),
// Slider on the side
Expanded(
child: Center(
child: RotatedBox(
quarterTurns: -1,
child: Slider(
value: _blindPosition,
activeColor: Theme.of(context).primaryColorDark,
thumbColor: Theme.of(context).primaryColorLight,
inactiveColor: Theme.of(context).primaryColorDark,
min: 0,
max: 10,
divisions: 10,
onChanged: (value) {
setState(() {
_blindPosition = value;
updateBlindPosition();
});
},
),
),
)
)
],
),
)
),
Container(
padding: EdgeInsets.all(25),
child: Text(
lastSetMessage
),
),
Container(
padding: EdgeInsets.all(10),
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SchedulesScreen()
)
);
},
child: Text(
"Set Schedules"
)
),
)
]
)
: SizedBox(
height: MediaQuery.of(context).size.height * 0.8,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.all(20),
child: Text(
"Peripheral Not Calibrated"
),
),
ElevatedButton(
onPressed: calibrate,
child: const Text("Calibrate")
)
],
)
)
)))
: BlindmasterProgressIndicator(),
floatingActionButton: Container(
padding: EdgeInsets.all(25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
FloatingActionButton(
heroTag: "rename",
tooltip: "Rename Peripheral",
onPressed: rename,
foregroundColor: Theme.of(context).highlightColor,
backgroundColor: Theme.of(context).primaryColorDark,
child: Icon(Icons.drive_file_rename_outline_sharp),
),
FloatingActionButton(
heroTag: "recalibrate",
tooltip: "Recalibrate Peripheral",
onPressed: recalibrate,
foregroundColor: Theme.of(context).highlightColor,
backgroundColor: Theme.of(context).primaryColorDark,
child: Icon(Icons.swap_vert),
),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
);
}
}