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

dexcom for Flutter allows you to use Dexcom Share to get your Dexcom CGM data, or anybody else's, to run your application. Includes time (in milliseconds since Enoch), reading, and trend. Use your ema [...]

example/example.md

Get Dexcom data (also sets up session)

Future<Map<String, dynamic>?> getDexcomData(username, password) async {
    Map settings = await getAllSettings();
    var dexcom = Dexcom(username], settings[password]);
    List<dynamic>? response;

    if (username == "" || password == "") {
        Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (context) => LoginPage(showBack: false)), // You can define LoginPage somewhere else in your code
        );
        return {};
    }
  
    try {
        await dexcom.createSession();
        print("Created session with dexcom: $dexcom");
    } catch (e) {
        showAlertDialogue(context, "Login error:", "An error occurred while logging in: $e: Did you enter the correct username and password? If not, go to Settings > Log In With Dexcom.", false, {"show": true, "text": e}); // You can define showAlertDialogue somewhere else in your code
    }

    try {
        response = await dexcom.getGlucoseReadings(maxCount: 2);
        print("Read data with dexcom: $dexcom");
    } catch (e) {
        showAlertDialogue(context, "Login error:", "An error occurred while logging in: $e: Did you enter the correct username and password? If not, go to Settings > Log In With Dexcom.", false, {"show": true, "text": e}); // You can define showAlertDialogue somewhere else in your code
    }

    if (response != null) {
        print(response);

        String wtString = response[0]['ST'];
        RegExp regExp = RegExp(r'Date\((\d+)\)');
        Match? match = regExp.firstMatch(wtString);
        
        if (match != null) {
            int milliseconds = int.parse(match.group(1)!);
            int seconds = milliseconds ~/ 1000;
            print('Time in seconds: $seconds');
            readingTime = seconds;
        } else {
            print('Invalid date format');
        }
        
        Map<String, dynamic> data = {
            "bg": response[0]["Value"],
            "trend": getTrend(response[0]["Trend"]),
            "previousreading": response[1]["Value"],
            "boundaries": {
            "superlow": settings["superlow"],
            "low": settings["low"],
            "high": settings["high"],
            "superhigh": settings["superhigh"],
            },
            "autodim": {
            "autodimon": settings["autodimon"],
            "autodimvalue": settings["autodimvalue"],
            "autodimtime": settings["autodimtime"],
            "stayawake": settings["stayawake"],
            }
        };

        print(data);
        prevData = data;
        return data;
    } else {
        return {"error": "response is null"};
    }
}

Verify login (creates Dexcom session and gets data to verify that the user is fully logged in)

Future<void> verifyLogin(username, password) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    var dexcom = Dexcom(username, password);

    ScaffoldMessenger.of(context).clearSnackBars();
    ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(content: Text('Loading...')),
    );
  
    try {
        await dexcom.createSession();
        print("Created session with dexcom: $dexcom");
    } catch (e) {
        showAlertDialogue(context, "Login error:", "An error occurred while logging in: $e (did you enter the correct username and password?)", false, {"show": true, "text": e}); // You can define showAlertDialogue somewhere else in your code
    }

    try {
        await dexcom.getGlucoseReadings(maxCount: 2);
        print("Read data with dexcom: $dexcom");

        // Save to localStorage for other functions and pages to use
        // You can replace with your own logic, E.G. saving it to a global variable
        await prefs.setString('username', username);
        await prefs.setString('password', password);
        
        ScaffoldMessenger.of(context).clearSnackBars();
        ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(content: Text('Logged in!')),
      ) ;

        Navigator.pop(context);
    } catch (e) {
        showAlertDialogue(context, "Login error:", "An error occurred while retrieving data: $e", false, {"show": true, "text": e}); // You can define showAlertDialogue somewhere else in your code
    }
}
0
likes
0
points
310
downloads

Publisher

unverified uploader

Weekly Downloads

dexcom for Flutter allows you to use Dexcom Share to get your Dexcom CGM data, or anybody else's, to run your application. Includes time (in milliseconds since Enoch), reading, and trend. Use your email and password to have access to all your glucose data!

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_test, http, intl, uuid

More

Packages that depend on dexcom