dopos_weight_scale 0.0.3 copy "dopos_weight_scale: ^0.0.3" to clipboard
dopos_weight_scale: ^0.0.3 copied to clipboard

***** EASY TO USE ***** The dopos_weight_scale plugin for interacting with weight scales via USB and COM ports on Android and Windows.

example/lib/main.dart

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

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('DoPOS Weight Scale')),
        body: DeviceListScreen(),
      ),
    );
  }
}

class DeviceListScreen extends StatefulWidget {
  @override
  _DeviceListScreenState createState() => _DeviceListScreenState();
}

class _DeviceListScreenState extends State<DeviceListScreen> {
  List<String> devices = [];
  DoposWeightScale _doposWeightScale = DoposWeightScale();
  TextEditingController wv = new TextEditingController();

  Future<void> fetchDevices() async {
    devices = await _doposWeightScale.listDevices();
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        ElevatedButton(
          onPressed: fetchDevices,
          child: const Text('List Devices'),
        ),
        Expanded(
          child: ListView.builder(
            itemCount: devices.length,
            itemBuilder: (_, index) {
              return ListTile(
                title: Text(devices[index]),
                onTap: () {
                  // Call the method or handle the tap event
                  _onDeviceTapped(index);
                },
              );
            },
          ),
        ),
        Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
          child: TextField(
            controller: wv,
            textAlign: TextAlign.center,
            style: const TextStyle(
                fontSize: 20, fontWeight: FontWeight.bold, color: Colors.red),
            decoration: const InputDecoration(
              border: OutlineInputBorder(),
            ),
          ),
        ),
      ],
    );
  }

  // Method to handle the device tap
  void _onDeviceTapped(int index) async {
    String selectedDevice = devices[index];
    String myWeight = await _doposWeightScale.getWeight(selectedDevice);
    // String myWeight = await _doposWeightScale.readWeight(index);
    log(myWeight);
    wv.text = myWeight;
    setState(() {});
  }
}
0
likes
140
points
126
downloads

Publisher

unverified uploader

Weekly Downloads

***** EASY TO USE ***** The dopos_weight_scale plugin for interacting with weight scales via USB and COM ports on Android and Windows.

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on dopos_weight_scale