finpong_plus 0.1.9 finpong_plus: ^0.1.9 copied to clipboard
Finpong Plus Widget
import 'dart:convert';
import 'package:finpong_plus/finpong_plus.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
void main() {
runApp(const MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String sampleToken = '';
String inputToken = '';
String inputEntry = '';
FinpongPlusController finpongPlusController = FinpongPlusController();
TextEditingController tokenInputController = TextEditingController();
TextEditingController entryInputController = TextEditingController();
ValueNotifier<bool> isLoading = ValueNotifier(true);
@override
void initState() {
super.initState();
_getPreferencesData();
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Container(
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: const EdgeInsets.only(top: 100),
child: Card(
child: TextField(
controller: entryInputController,
onChanged: (text) {
setState(() {
inputEntry = text;
});
},
decoration: const InputDecoration(
border: OutlineInputBorder(), labelText: 'entry'),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 10),
child: Card(
child: TextField(
controller: tokenInputController,
onChanged: (text) {
setState(() {
inputToken = text;
});
},
decoration: const InputDecoration(
border: OutlineInputBorder(), labelText: 'token'),
),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(
width: 10,
),
ElevatedButton(
child: Text('Stg'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => _finpongPlusWidget(inputToken, ServerMode.staging)
)
);
},
),
const SizedBox(
width: 10,
),
ElevatedButton(
child: Text('Release'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => _finpongPlusWidget(inputToken, ServerMode.release)
)
);
},
),
],
),
],
),
),
);
}
Widget _finpongPlusWidget(String token, ServerMode serverMode) {
_savePreferencesData();
isLoading.value = true;
return SafeArea(
child: Stack(
children: [
FinpongPlusWidget(
finpongPlusController: finpongPlusController,
token: token,
entry: inputEntry,
serverMode: serverMode,
backgorundColor: Colors.white,
onUriScheme: (type, scheme) {
/**
* 앱스킴으로 해당 사설 인증앱 실행 코드 작성
* 앱 미설치일 경우 설치 유도 코드 작성
*/
// 사설 인증서 호출(앱스킴 실행) 참고용 입니다.
canLaunchUrl(Uri.parse(scheme)).then((bool result) {
setState(() async {
if (result) {
if (!await launchUrl(Uri.parse(scheme), mode: LaunchMode.externalApplication)) {
throw Exception('Could not launch $scheme');
}
} else {
!await launchUrl(
Uri.parse('type별 스토어 url'),
mode: LaunchMode.externalApplication,
);
}
});
});
},
onCustomAction: (pageId, params) {
//사전 정의된 핀퐁플러스의 액션을 앱에서 처리를 위함
// 예시
if (pageId == 'PA-001') {
var testData = {"data1": 1, "data2": true};
String jsonString = jsonEncode(testData);
finpongPlusController.runJavaScript('fileDataConnect', jsonString);
}
if (pageId == 'IV-001') { // 핀퐁플러스 로딩 완료 시 발생하는 custom action
isLoading.value = false;
}
},
onCloseAction: () {
//핀퐁플러스 닫기
Navigator.pop(context);
},
onPageLoadStarted: () {
//핀퐁플러스 페이지 로드 시작
},
onPageLoadFinished: () {
//핀퐁플러스 페이지 로드 종료
isLoading.value = false;
},
),
// 핀퐁플러스 로딩 뷰 설정
ValueListenableBuilder(
valueListenable: isLoading,
builder: (BuildContext context, value, Widget? child) {
return Visibility(visible: isLoading.value, child: loadingView());
},
),
],
)
);
}
Future<void> _savePreferencesData() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setString('token', inputToken);
prefs.setString('entry', inputEntry);
}
Future<void> _getPreferencesData() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
inputToken = prefs.getString('token') ?? '';
inputEntry = prefs.getString('entry') ?? '';
tokenInputController.text = inputToken;
entryInputController.text = inputEntry;
}
Widget loadingView() {
return Scaffold(
body: Container(
color: Colors.white,
width: double.infinity,
height: double.infinity,
alignment: Alignment.center,
child: const Text(
"핀퐁플러스 로딩중입니다.\n잠시만 기다려 주세요.",
textAlign: TextAlign.center,
style: TextStyle(color: Colors.black, fontSize: 18, fontWeight: FontWeight.bold),
)
),
);
}
}