0% found this document useful (0 votes)
4 views3 pages

التحكم في LED باستخدام Flutter

Uploaded by

christ.github
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

التحكم في LED باستخدام Flutter

Uploaded by

christ.github
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import 'package:flutter/material.

dart';
import 'package:http/[Link]' as http;

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
title: '‫ تحكم في‬LED',
home: LedControlPage(),
);
}
}

class LedControlPage extends StatefulWidget {


@override
_LedControlPageState createState() => _LedControlPageState();
}

class _LedControlPageState extends State<LedControlPage> {


String esp32IP = "[Link]"; // ‫ غير هذا العنوان ل‬IP ESP32
bool isLoading = false;
String ledStatus = "‫;"غير معروف‬

Future<void> controlLed(String action) async {


setState(() {
isLoading = true;
});

try {
final response = await [Link](
[Link]('[Link]
headers: {'Content-Type': 'application/json'},
);

if ([Link] == 200) {
setState(() {
ledStatus = action;
});
print('‫ تم‬$action LED ‫;)'بنجاح‬
} else {
print('‫فشل في التحكم‬: ${[Link]}');
}
} catch (e) {
print('‫خطأ في االتصال‬: $e');
} finally {
setState(() {
isLoading = false;
});
}
}

Future<void> getLedStatus() async {


try {
final response = await [Link](
[Link]('[Link]
);

if ([Link] == 200) {
// ‫ تحليل ال‬response ‫ لمعرفة حالة ال‬LED
setState(() {
ledStatus = [Link]('on') ? 'on' : 'off';
});
}
} catch (e) {
print('‫خطأ في جلب الحالة‬: $e');
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('‫ تحكم في‬LED'),
backgroundColor: [Link],
),
body: Center(
child: Column(
mainAxisAlignment: [Link],
children: [
Text(
'‫ حالة ال‬LED: $ledStatus',
style: TextStyle(fontSize: 20),
),
SizedBox(height: 30),
if (isLoading) CircularProgressIndicator(),
if (!isLoading) ...[
ElevatedButton(
onPressed: () => controlLed('on'),
child: Text('‫ تشغيل ال‬LED'),
style: [Link](
backgroundColor: [Link],
foregroundColor: [Link],
padding: [Link](horizontal: 30, vertical: 15),
),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () => controlLed('off'),
child: Text('‫ إطفاء ال‬LED'),
style: [Link](
backgroundColor: [Link],
foregroundColor: [Link],
padding: [Link](horizontal: 30, vertical: 15),
),
),
],
SizedBox(height: 20),
ElevatedButton(
onPressed: getLedStatus,
child: Text('‫)'تحديث الحالة‬,
),
],
),
),
);
}
}

You might also like