tradein_plugin 0.0.9 copy "tradein_plugin: ^0.0.9" to clipboard
tradein_plugin: ^0.0.9 copied to clipboard

Trade in plug in package is for usage of native modules like android and ios code are using in flutter app

example/lib/main.dart

import 'dart:io';

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

import 'package:flutter/services.dart';
import 'package:tradein_plugin/tradein_plugin.dart';
import 'package:tradein_plugin/modal/student.dart';

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

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _selectedText = '';
  String _dataFromAndroidNativeCode = 'Unknown';
  String _resultFromAndroidNativeCode = 'Unknown';
  List<Map<String, dynamic>> _arr = [
    {'name': 'man', 'age': 28},
    {'name': 'ram', 'age': 34},
  ];
  List<Map<String, dynamic>> arr = [
    {
      'name': 'Citroen C5 Aircross',
      'description':
      'Mahindra has provided the XUV700 with two powertrain options: 200PS/380Nm 2.0-litre turbo-petrol and a 2.2-litre diesel developing up to 185PS and 450Nm. Both engines get 6-speed manual and 6-speed automatic transmission options'
    },
    {
      'name': 'Mahindra XUV700',
      'description':
      'Mahindra has provided the XUV700 with two powertrain options: 200PS/380Nm 2.0-litre turbo-petrol and a 2.2-litre diesel developing up to 185PS and 450Nm. Both engines get 6-speed manual and 6-speed automatic transmission options'
    },
    {
      'name': 'Kia Seltos',
      'description':
      'Kia has provided the 2021 Seltos with three powertrains: a 115PS/144Nm 1.5-litre petrol, 140PS/242Nm 1.4-litre turbo-petrol, and a 115PS/250Nm 1.5-litre diesel unit. All engines come mated with a standard 6-speed manual gearbox'
    },
    {
      'name': 'Renault Kiger',
      'description':
      'The Renault Kiger is available with two petrol engines: 72PS/96Nm 1.0-litre naturally aspirated and 100PS/160Nm 1.0-litre turbo-petrol units. It comes with a standard 5-speed manual gearbox.'
    },
  ];
  final student = Student(name: 'man', age: 20);

  Map<String, dynamic> json = {'name': 'man', 'age': 28};

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

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    String _dataFromAndroid = 'Unknown';
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await TradeinPlugin.platformVersion ?? 'Unknown platform version';
      // TradeinPlugin.passValuesToNative(student,
      //     value: 'hi', arr: arr, json: json, isTrue: true);
      TradeinPlugin.passValuesToNative(student,
          value: 'hi', arr: _arr, json: json, isTrue: true);
      _getTradinPluginSDKValues();
      print("Venky calling for data - " + _dataFromAndroid);
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // 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(() {
    //   print("Venky calling for data - "+_dataFromAndroid);
    //   _dataFromAndroidNativeCode = _dataFromAndroid;
    //   print("Venky calling for data - "+_dataFromAndroidNativeCode);
    // });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Trade In Host app'),
        ),
        body: Center(
            child: Column(children: <Widget>[
              Container(
                margin: EdgeInsets.all(25),
                child: Text(
                  'Welcome To Trade In Host App',
                  style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
                ),
              ),
              Container(
                margin: EdgeInsets.all(25),
                child: FlatButton(
                  child: Text(Platform.isIOS ? 'Car List' : 'Flutter Plug In POC 1 - Android',
                    style: TextStyle(fontSize: 20.0),
                  ),
                  color: Colors.blueAccent,
                  textColor: Colors.white,
                  onPressed: _showNativeView,
                ),
              ),
              Container(
                margin: EdgeInsets.all(25),
                child: FlatButton(
                  child: Text('Flutter Plug In POC 2 - Android',
                    style: TextStyle(fontSize: 20.0),
                  ),
                  color: Colors.blueAccent,
                  textColor: Colors.white,
                  onPressed: _showAndroidNativeView,
                ),
              ),
              Container(
                margin: EdgeInsets.all(25),
                child: FlatButton(
                  child: Text(
                    'Trade In SDK (Android)',
                    style: TextStyle(fontSize: 20.0),
                  ),
                  color: Colors.blueAccent,
                  textColor: Colors.white,
                  onPressed: _showTradeInView,
                ),
              ),
              _selectedText != ''
                  ? RichText(
                  textAlign: TextAlign.center,
                  text: TextSpan(
                      style: TextStyle(
                          fontSize: 16,
                          color: Colors.black,
                          fontWeight: FontWeight.w500),
                      children: [
                        TextSpan(text: 'Seleted Car: '),
                        TextSpan(
                            text: _selectedText,
                            style: TextStyle(
                                fontSize: 18,
                                fontWeight: FontWeight.bold,
                                color: Colors.blue)),
                      ]))
                  : Text(''),
              // Text(
              //   _selectedText,style: TextStyle(fontSize: 18,),textAlign:TextAlign.center,
              // )
            ])),
      ),
    );
  }

  Future<void> _showAndroidNativeView() async {
    print("Venky calling for data _showNativeView");
    final student = Student(name: 'man', age: 20);
    TradeinPlugin.passValuesToNative(
        student, value: 'hi', arr: _arr, json: json, isTrue: true);
  }

  Future<void> _showTradeInView() async {
    print("Venky calling for data _showNativeView");
    String data1;
    try {
      // TradeinPlugin.loadTradinPluginSDK();
      final String? data = await TradeinPlugin.loadTradinPluginSDKWithValues(
          "userName", "iLotid", "vin"); //sending data from flutter here
      setState(() {
        print("Venky calling for data _showNativeView - " + data!);
        _resultFromAndroidNativeCode = data;
        print("Venky calling for data _showNativeView - " +
            _dataFromAndroidNativeCode);
      });
    } on PlatformException catch (e) {
      data1 = "Android is not responding please check the code";
    }
  }

  Future<String?> _getTradinPluginSDKValues() async {
    print("Venky calling for data new");
    String data;
    try {
      data = (await TradeinPlugin
          .getTradinPluginSDKValues)!; //sending data from flutter here
    } on PlatformException catch (e) {
      data = "Android is not responding please check the code";
    }
    setState(() {
      print("Venky calling for data new - " + data);
      _dataFromAndroidNativeCode = data;
      print("Venky calling for data new - " + _dataFromAndroidNativeCode);
    });
  }

  Future<Null> _showNativeView() async {
    if (Platform.isIOS) {
      final value = await TradeinPlugin.passValuesToNative(student,
          value: 'hi', arr: arr, json: json, isTrue: true);
      setState(() {
        _selectedText = value ?? '';
      });
    } else {
      TradeinPlugin.loadTradinPluginSDK();
    }
  }
}
0
likes
110
pub points
0%
popularity

Publisher

unverified uploader

Trade in plug in package is for usage of native modules like android and ios code are using in flutter app

Repository (GitLab)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on tradein_plugin