device_market_name 0.0.6 copy "device_market_name: ^0.0.6" to clipboard
device_market_name: ^0.0.6 copied to clipboard

Small package which return market name for model code e.g. SM-G970F=>Galaxy s10e, iPhone13,2=>iPhone 12. Works for android with gms & iOS devices

example/lib/main.dart

import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:device_market_name/device_market_name.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DeviceMarketName',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'DeviceMarketName'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  String? marketName;
  String? modelCode;

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

  asyncInit() async {
    ///E.g. Get marketName for another platform & device
    print(await DeviceMarketName()
        .getMarketName('iPhone14,2', platform: TargetPlatform.iOS));
    print(await DeviceMarketName()
        .getMarketName('SM-F900U1', platform: TargetPlatform.android));

    ///
    ///E.g. Get marketName for current device
    ///To get device modelCode use fo e.g:
    ///[device_info_plus] - https://pub.dev/packages/device_info_plus
    ///
    try {
      if (Platform.isAndroid) {
        final deviceInfo = await DeviceInfoPlugin().androidInfo;
        modelCode = deviceInfo.model;
      } else if (Platform.isIOS) {
        final deviceInfo = await DeviceInfoPlugin().iosInfo;
        modelCode = deviceInfo.utsname.machine;
      }
    } catch (_) {
      modelCode = 'unknown';
    }
    if (mounted) setState(() {});

    try {
      marketName = await DeviceMarketName().getMarketName(modelCode!);
      ///
      /// [withoutNetwork] work only at iOS devices
      /// marketName = await DeviceMarketName()
      ///     .getMarketName(modelCode!, withoutNetwork: true);
      ///
    } catch (_) {
      marketName = 'unknown';
    }
    if (mounted) setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'ModelCode: $modelCode',
            ),
            Text(
              'MarketName: $marketName',
            ),
          ],
        ),
      ),
    );
  }
}
2
likes
130
pub points
54%
popularity

Publisher

unverified uploader

Small package which return market name for model code e.g. SM-G970F=>Galaxy s10e, iPhone13,2=>iPhone 12. Works for android with gms & iOS devices

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, http, path, path_provider, sqflite

More

Packages that depend on device_market_name