tuya_plugin 0.0.4 copy "tuya_plugin: ^0.0.4" to clipboard
tuya_plugin: ^0.0.4 copied to clipboard

tuya iot control.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:tuya_plugin/tuya_plugin.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: MyHomePage(
          title: 'Running on: $_platformVersion\n',
        ),
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String? item;
  TextEditingController code = TextEditingController();
  TextEditingController email = TextEditingController();
  TextEditingController password = TextEditingController();
  TextEditingController homeName = TextEditingController();

  @override
  void initState() {
    super.initState();
    TuyaPlugin.initialize().then((result) {
      print(result);
    }).catchError((error) {
      print("initialize error : $error");
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              InkWell(
                onTap: () async {
                  await TuyaPlugin.sendVerificationCode(email.text).then((result) {
                    print(result);
                  }).catchError((error) {
                    print("sendVerificationCode error : $error");
                  });
                },
                child: Container(
                  height: 50,
                  width: 100,
                  child: Text("getCode"),
                ),
              ),
              SizedBox(
                width: 200,
                child: TextField(
                  controller: code,
                  decoration: const InputDecoration(
                      border: InputBorder.none, labelText: 'Enter Code', hintText: 'Enter Your Code'),
                ),
              ),
              SizedBox(
                width: 200,
                child: TextField(
                  controller: email,
                  decoration: const InputDecoration(
                      border: InputBorder.none, labelText: 'Enter Email', hintText: 'Enter Your Email'),
                ),
              ),
              SizedBox(
                width: 200,
                child: TextField(
                  controller: password,
                  decoration: const InputDecoration(
                      border: InputBorder.none, labelText: 'Enter Password', hintText: 'Enter Your password'),
                ),
              ),
              InkWell(
                onTap: () async {
                  await TuyaPlugin.register(email.text, password.text, code.text).then((result) {
                    print(result);
                  }).catchError((error) {
                    print("register error : $error");
                  });
                },
                child: Container(
                  height: 50,
                  width: 100,
                  child: Text("register"),
                ),
              ),
              InkWell(
                onTap: () async {
                  await TuyaPlugin.login(email.text, password.text).then((result) {
                    print(result);
                  }).catchError((error) {
                    print("login error : $error");
                  });
                },
                child: Container(
                  height: 50,
                  width: 100,
                  child: Text("login"),
                ),
              ),
              TextField(
                controller: homeName,
                decoration: const InputDecoration(
                    border: InputBorder.none, labelText: 'Enter Home Name', hintText: 'Enter Your Home Name'),
              ),
              InkWell(
                onTap: () async {
                  await TuyaPlugin.createHome(homeName.text).then((result) {
                    print(result);
                  }).catchError((error) {
                    print("create error : $error");
                  });
                },
                child: Container(
                  height: 50,
                  width: 100,
                  child: Text("create home"),
                ),
              ),
              InkWell(
                onTap: () async {
                  await TuyaPlugin.deletedHome().then((result) {
                    print(result);
                  }).catchError((error) {
                    print("list home error : $error");
                  });
                },
                child: Container(
                  height: 50,
                  width: 100,
                  child: Text("deletedHome"),
                ),
              ),
              InkWell(
                onTap: () async {
                  await TuyaPlugin.listHome().then((result) {
                    print(result);
                  }).catchError((error) {
                    print("list home error : $error");
                  });
                },
                child: Container(
                  height: 50,
                  width: 100,
                  child: Text("list Home"),
                ),
              ),
              InkWell(
                onTap: () async {
                  await TuyaPlugin.addRoom("Palm Room").then((result) {
                    print(result);
                  }).catchError((error) {
                    print("login error : $error");
                  });
                },
                child: Container(
                  height: 50,
                  width: 100,
                  child: Text("add room"),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
pub points
34%
popularity

Publisher

unverified uploader

tuya iot control.

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on tuya_plugin