d2uhf 0.0.1 copy "d2uhf: ^0.0.1" to clipboard
d2uhf: ^0.0.1 copied to clipboard

outdated

D2 UHF plugin.

example/lib/main.dart

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

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: "d2 UHF Test",
      theme: ThemeData(primarySwatch: Colors.deepPurple),
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int _currentPower = 1;
  double _currentSliderValue = 0;
  String _setPower = "";
  String _currentTag = "Нет данных";

  @override
  void initState() {
    super.initState();
    _initGetPower();
  }

  Future<void> _initGetPower() async {
    int? currentPower;
    try {
      var readPower = D2uhf.readPower;
      currentPower = await readPower;
    } on PlatformException {
      currentPower = 0;
    }
    if (!mounted) return;

    setState(() {
      _currentPower = currentPower!;
      _currentSliderValue = _currentPower.toDouble();
    });
  }

  Future<int> _writePower(int newPower) async {
    int power = 0;
    try {
      power = (await D2uhf.writePower(newPower));
    } on PlatformException {
      power = 0;
    }
    return power;
  }

  Future<String> _getTag() async {
    String tag = "";
    try {
      tag = await D2uhf.readTag;
    } on PlatformException {
      tag = 'Нет данных';
    }
    return tag;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Тестирование")),
      body: Container(
        child: Column(
          children: <Widget>[
            Container(
              child: Text(
                'Текущая мощность: $_currentPower\n',
                style: TextStyle(fontWeight: FontWeight.bold, fontSize: 30),
              ),
            ),
            Container(
              child: Slider(
                value: _currentSliderValue,
                min: 0,
                max: 33,
                //divisions: 30,
                label: _currentSliderValue.round().toString(),
                onChanged: (double value) {
                  setState(() {
                    _currentSliderValue = value;
                    _setPower = (_currentSliderValue.round()).toString();
                  });
                },
              ),
            ),
            Container(
              child: ElevatedButton(
                child: Text(
                  'Устанвить мощность $_setPower',
                  style: TextStyle(fontSize: 22),
                ),
                onPressed: () {
                  _writePower(_currentSliderValue.round()).then((value) {
                    setState(() {
                      _currentPower = value;
                    });
                  });
                },
              ),
            ),
            const Divider(
              height: 20,
              thickness: 5,
              indent: 20,
              endIndent: 20,
            ),
            Container(
              padding: const EdgeInsets.only(left: 20),
              child: Align(
                alignment: AlignmentDirectional.centerStart,
              ),
            ),
            Expanded(
              child: Container(
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    " Метка:\n\n $_currentTag",
                    style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20),
                  ),
                ),
              ),
            ),
            SizedBox(
              width: double.infinity,
              height: 100,
              child: ElevatedButton(
                child: Text(
                  'Считать метку',
                  style: TextStyle(fontSize: 22),
                ),
                onPressed: () {
                  _getTag().then((value) {
                    setState(() {
                      _currentTag = value;
                    });
                  });
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
3
likes
0
pub points
0%
popularity

Publisher

verified publisheroldcyber.xyz

D2 UHF plugin.

Homepage

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on d2uhf