tnk_flutter_rwd 0.2.6 copy "tnk_flutter_rwd: ^0.2.6" to clipboard
tnk_flutter_rwd: ^0.2.6 copied to clipboard

outdated

tnk rwd sdk flutter plugin support android.

example/lib/main.dart

import 'dart:collection';
import 'dart:convert';

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

import 'package:flutter/services.dart';
import 'package:tnk_flutter_rwd/tnk_flutter_rwd.dart';
import 'tnk_flutter_rwd_analytics.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();

}

class _MyAppState extends State<MyApp> {
  final _tnkFlutterRwdPlugin = TnkFlutterRwd();

  String _tnkResult = 'Unknown';
  int _myPoint = 0;
  int _queryPoint = 0;
  final String _itemId = "item.0001";
  final int _cost = 2;

  int _selectedIndex = 0;


  @override
  void initState() {
    MethodChannel channel = const MethodChannel('tnk_flutter_rwd');
    channel.setMethodCallHandler(getOfferWallEvent);
    super.initState();
  }

  Future<void> getOfferWallEvent(MethodCall methodCall) async {

    if(TnkMethodChannelEvent.didOfferwallRemoved(methodCall))
    {
      // TODO 오퍼월 close callback
      print( "offer window closed" );
      print(methodCall.arguments);
    }

    setState(() {
      _tnkResult = methodCall.arguments;
    });
  }


  Future<void> showAdList() async {
    String platformVersion;

    try {
      await _tnkFlutterRwdPlugin.setUserName("testUser");
      await _tnkFlutterRwdPlugin.setCOPPA(false);
      platformVersion = await _tnkFlutterRwdPlugin.showAdList("미션 수행하기") ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _tnkResult = platformVersion;
    });
  }

  Future<void> showATTPopup() async {
    try {
      await _tnkFlutterRwdPlugin.showATTPopup();
    } on Exception {
      return;
    }
  }

  Future<void> getEarnPoint() async {
    int point;
    try {
      point = await _tnkFlutterRwdPlugin.getEarnPoint() ?? 0;
    } on PlatformException {
      point = 0;
    }

    setState(() {
      _myPoint = point;
    });
  }

  Future<void> setNoUsePointIcon() async {
    try {
      await _tnkFlutterRwdPlugin.setNoUsePointIcon();
    } on Exception {
      return;
    }
  }

  Future<void> setNoUsePrivacyAlert() async {
    try {
      await _tnkFlutterRwdPlugin.setNoUsePrivacyAlert();
    } on Exception {
      return;
    }
  }

  Future<void> getQueryPoint() async {
    int point;
    try {
      point = await _tnkFlutterRwdPlugin.getQueryPoint() ?? 0;
    } on PlatformException {
      point = 0;
    }

    setState(() {
      _queryPoint = point;
    });
  }

  Future<void> purchaseItem(String itemId, int cost) async {
    try {
      await _tnkFlutterRwdPlugin.purchaseItem(itemId, cost);
    } on Exception {
      return;
    }
  }

  Future<void> withdrawPoints(String description) async {
    try {
      await _tnkFlutterRwdPlugin.withdrawPoints(description);
    } on Exception {
      return;
    }
  }

  void _showDialog(BuildContext context) {
    showDialog(
        context: context,
        builder: (BuildContext ctx) {
          return const AlertDialog(
            title: Text("abc"),
            content: Text(' 항목을 선택했습니다.'),
          );
        });
  }

  Future<void> setCustomUI() async {
    try {
      HashMap<String, String> paramMap = HashMap();
      //0xff252542
      paramMap.addAll({
        // 카테고리 컬러
        "category_select_font": "#495057",
        // 선택된 필터 배경색
        "filter_select_background": "#495057",
        // 선택된 필터 폰트 컬러
        "filter_select_font": "#FFFFFF",
        // 선택안한 필터 폰트 컬러
        "filter_not_select_font": "#495057",
        // 선택안한 필터 배경색
        "filter_not_select_background": "#FFFFFF",
        // 광고상세페이지 광고타이틀 폰트 컬러
        "adinfo_title_font": "#212529",
        // 광고상세페이지 광고액션 폰트 컬러
        "adinfo_desc_font": "#5F0D80",
        // 광고상세페이지 포인트 단위 컬러
        "adinfo_point_unit_font": "#5F0D80",
        // 광고상세페이지 포인트 액수 폰트 컬러
        "adinfo_point_amount_font": "#5F0D80",
        // 광고상세페이지 버튼 백그라운드 컬러
        "adinfo_button_background": "#5F0D80",
        // 광고상세페이지 버튼 백그라운드 컬러
        "adinfo_button_title_font": "#FFFFFF",
        // 광고상세페이지 버튼 백그라운드 컬러
        "adinfo_button_desc_font": "#FFFFFF",
        "adinfo_button_gradient_option": "L",

        // "adlist_title_font":"#212529", // 광고리스트 광고타이틀 폰트 컬러
        // "adlist_desc_font":"#61666A", // 광고리스트 광고액션 폰트 컬러
        // "adlist_point_unit_font":"#5F0D80", // 광고리스트 포인트 단위 폰트 컬러
        // "adlist_point_amount_font":"#5F0D80", // 광고리스트 포인트 액수 폰트 컬러
        // "point_icon_name":"", // 포인트 아이콘 이미지 이름
        // "point_icon_use_yn":"N", // 포인트 아이콘 사용여부 ( 포인트아이콘 사용시 포인트 단위는 사용못함 )
      });
      await _tnkFlutterRwdPlugin.setCustomUI(paramMap);
    } on Exception {
      return;
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter RWD Plugin'),
          actions: [
            IconButton(
                onPressed: () {
                  // setNoUsePointIcon();
                  setCustomUI();
                },
                icon: const Icon(Icons.dashboard_customize))
          ],
        ),
        drawer: Drawer(
          child: ListView(
            padding: EdgeInsets.zero,
            children: <Widget>[
              const UserAccountsDrawerHeader(
                currentAccountPicture: CircleAvatar(
                  backgroundColor: Colors.white,
                ),
                accountName: Text("tnkfactory"),
                accountEmail: Text('[email protected]'),
                decoration: BoxDecoration(
                    color: Colors.blue,
                    borderRadius: BorderRadius.only(
                        bottomLeft: Radius.circular(40.0),
                        bottomRight: Radius.circular(40.0))),
              ),
              ListTile(
                leading: const Icon(
                  Icons.tv,
                  color: Colors.blueGrey,
                ),
                title: const Text('OfferWall'),
                onTap: () => "aaa",
              ),
            ],
          ),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              Row(children: [
                DataTable(
                  columns: const [
                    DataColumn(label: Text('tnkResult')),
                    DataColumn(label: Text('적립가능한 Point')),
                    DataColumn(label: Text('사용가능한 Point')),
                  ],
                  rows: [
                    DataRow(cells: [
                      DataCell(Text(_tnkResult)),
                      DataCell(Text('$_myPoint')),
                      DataCell(Text('$_queryPoint')),
                    ]),
                  ],
                ),
              ]),
              ButtonBar(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      ElevatedButton(
                        onPressed: () {},
                        style: ElevatedButton.styleFrom(
                            foregroundColor: Colors.white,
                            backgroundColor: Colors.redAccent,
                            shadowColor: Colors.redAccent,
                            elevation: 5),
                        child: const Text("TEST"),
                      ),
                      ElevatedButton(
                          onPressed: () {
                            getEarnPoint();
                          },
                          style: ElevatedButton.styleFrom(
                              foregroundColor: Colors.white,
                              backgroundColor: Colors.blueAccent,
                              shadowColor: Colors.blueAccent,
                              elevation: 10),
                          child: const Text('적립가능한 포인트')),
                      ElevatedButton(
                          onPressed: () {
                            getQueryPoint();
                          },
                          style: ElevatedButton.styleFrom(
                              foregroundColor: Colors.white,
                              backgroundColor: Colors.blueAccent,
                              shadowColor: Colors.blueAccent,
                              elevation: 10),
                          child: const Text('사용가능한 포인트')),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      ElevatedButton(
                          onPressed: () {
                            purchaseItem(_itemId, _cost);
                          },
                          style: ElevatedButton.styleFrom(
                              foregroundColor: Colors.white,
                              backgroundColor: Colors.redAccent,
                              shadowColor: Colors.redAccent,
                              elevation: 10),
                          child: const Text('테스트구매')),
                      ElevatedButton(
                          onPressed: () {
                            withdrawPoints("테스트 인출");
                          },
                          style: ElevatedButton.styleFrom(
                              foregroundColor: Colors.white,
                              backgroundColor: Colors.redAccent,
                              shadowColor: Colors.redAccent,
                              elevation: 10),
                          child: const Text('테스트인출')),
                    ],
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      ElevatedButton(
                          onPressed: showATTPopup,
                          style: ElevatedButton.styleFrom(
                              foregroundColor: Colors.white,
                              backgroundColor: Colors.grey,
                              shadowColor: Colors.grey,
                              elevation: 10),
                          child: const Text('ATT Popup')),
                      ElevatedButton(
                          onPressed: setNoUsePointIcon,
                          style: ElevatedButton.styleFrom(
                              foregroundColor: Colors.white,
                              backgroundColor: Colors.grey,
                              shadowColor: Colors.grey,
                              elevation: 10),
                          child: const Text('포인트아이콘 사용안함')),
                      ElevatedButton(
                        onPressed: () {},
                        style: ElevatedButton.styleFrom(
                          foregroundColor:Colors.white,
                          backgroundColor:Colors.amberAccent,
                          shadowColor:Colors.amberAccent,
                          elevation: 10),
                        child: const Text("abc"))
                    ],
                  )
                ],
              ),
            ],
          ),
        ),
        bottomNavigationBar: BottomNavigationBar(
          backgroundColor: Colors.white,
          unselectedItemColor: Colors.blueGrey,
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: '홈',
            ),
            BottomNavigationBarItem(icon: Icon(Icons.tv), label: 'Offerwall'),
            BottomNavigationBarItem(
                icon: Icon(Icons.notifications), label: '알림'),
          ],
          currentIndex: _selectedIndex,
          selectedItemColor: Colors.blue,
          onTap: _onItemTapped,
        ),
      ),
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });

    if (_selectedIndex == 1) {
      showAdList();
    }
  }
}