first commit

This commit is contained in:
kicap
2024-08-03 12:54:13 +08:00
commit 053ab5a6ac
40 changed files with 2936 additions and 0 deletions

View File

@ -0,0 +1,105 @@
import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart';
import 'package:traffic_light/app/themes/app_text.dart';
import './status_lampu_view_model.dart';
class StatusLampuView extends StatelessWidget {
const StatusLampuView({super.key});
@override
Widget build(BuildContext context) {
return ViewModelBuilder<StatusLampuViewModel>.reactive(
viewModelBuilder: () => StatusLampuViewModel(),
onViewModelReady: (StatusLampuViewModel model) async {
await model.init();
},
builder: (
BuildContext context,
StatusLampuViewModel model,
Widget? child,
) {
// create traffic light using column
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(20),
width: 150,
height: 400,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(20),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: model.light == 'Red'
? const Color.fromARGB(255, 249, 8, 8)
: Colors.red[100],
shape: BoxShape.circle,
),
),
const SizedBox(height: 20),
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: model.light == 'Yellow'
? const Color.fromARGB(255, 245, 220, 0)
: Colors.yellow[100],
shape: BoxShape.circle,
),
),
const SizedBox(height: 20),
Container(
width: 100,
height: 100,
decoration: BoxDecoration(
color: model.light == 'Green'
? const Color.fromARGB(255, 0, 255, 13)
: Colors.green[100],
shape: BoxShape.circle,
),
),
],
),
),
const SizedBox(height: 20),
Text(
model.no == null
? '...'
: model.strLength <= 2
? model.no!
: "...",
style: italicTextStyle.copyWith(
fontWeight: FontWeight.bold,
fontSize: 30,
),
),
const SizedBox(height: 20),
Text(
'Current RMS (A) : ${model.rms ?? '...'}',
style: boldTextStyle.copyWith(
fontSize: 20,
),
),
const SizedBox(height: 20),
Text(
'Status Traffic Light : ${model.plnStatus}',
style: boldTextStyle.copyWith(
fontSize: 20,
),
),
],
),
);
},
);
}
}

View File

@ -0,0 +1,35 @@
import 'package:traffic_light/app/core/custom_base_view_model.dart';
import '../../../../app/app.logger.dart';
class StatusLampuViewModel extends CustomBaseViewModel {
final log = getLogger('StatusLampuViewModel');
String plnStatus = "....";
int strLength = 0;
Future<void> init() async {
socketIoClient.on('datanya', (data) {
// log.d(data);
String rmsnya = data['rms'];
no = data['no'];
strLength = no!.length;
light = data['light'];
pln = data['pln'];
rms = double.parse(rmsnya);
log.d(rms);
if (pln == "") {
plnStatus = "....";
} else if (pln == "PLN OFF") {
plnStatus = "Listrik mati";
} else if (pln == "PLN ON" && rms! < 0.262) {
// 0.262 , 0.37
plnStatus = "Lampu terputus & rusak";
} else if (pln == "PLN ON" && rms! >= 0.262) {
plnStatus = "Lampu normal";
}
notifyListeners();
});
}
}