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

plugin for extract telephony cell info.

example/lib/main.dart

// ignore_for_file: avoid_print

import 'dart:convert';

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

import 'package:flutter/services.dart';
import 'package:nr_cellinfo/cellResponse.dart';
import 'package:nr_cellinfo/simInfoResponse.dart';
import 'package:nr_cellinfo/nr_cellinfo.dart';
import 'package:nr_cellinfo/models/common/cell_type.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  CellsResponse? _cellsResponse;

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

  String currentDBM = "";

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    CellsResponse? cellsResponse;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      String platformVersion = (await NrCellinfo.getCellInfo) ?? "";
      final body = json.decode(platformVersion);

      cellsResponse = CellsResponse.fromJson(body);

      CellType currentCellInFirstChip = cellsResponse.primaryCellList![0];
      if (currentCellInFirstChip.type == "LT  E") {
        currentDBM = "LTE dbm = " +
            currentCellInFirstChip.lte!.signalLTE!.dbm.toString();
      } else if (currentCellInFirstChip.type == "NR") {
        currentDBM =
            "NR dbm = " + currentCellInFirstChip.nr!.signalNR!.dbm.toString();
      } else if (currentCellInFirstChip.type == "WCDMA") {
        currentDBM = "WCDMA dbm = " +
            currentCellInFirstChip.wcdma!.signalWCDMA!.dbm.toString();

        print('currentDBM = ' + currentDBM);
      }

      String simInfo = (await NrCellinfo.getSIMInfo) ?? "";
      final simJson = json.decode(simInfo);
      print(
          "desply name ${SIMInfoResponse.fromJson(simJson).simInfoList![0].displayName}");
    } on PlatformException {
      _cellsResponse = null;
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _cellsResponse = cellsResponse;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: _cellsResponse != null
            ? Center(
                child: Text(
                    'david = $currentDBM\n primary = ${_cellsResponse!.primaryCellList!.length.toString()} \n neighbor = ${_cellsResponse!.neighboringCellList!.length}'),
              )
            : null,
      ),
    );
  }
}
1
likes
100
pub points
0%
popularity

Publisher

unverified uploader

plugin for extract telephony cell info.

Documentation

API reference

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on nr_cellinfo