增加广告组件,个人中心

This commit is contained in:
唐明明
2022-05-27 17:52:17 +08:00
parent 4a635f3570
commit d64bf95b25
269 changed files with 3960 additions and 309 deletions

170
lib/ad/ad.dart Normal file
View File

@@ -0,0 +1,170 @@
import 'package:flutter/services.dart';
typedef AdCallback = void Function(String id);
typedef AdErrorCallback = void Function(String id, int code, String message);
/// API for showing various types of advertisements
class AdSdk {
static int _channelId = 0;
static MethodChannel _methodChannel =
new MethodChannel("flutter_adsjm_plugin/method");
/// set user id on login and logout
// static void setUserId(String userId) {
// _methodChannel.invokeMethod("setUserId", {"userId": userId});
// }
/// show reward video ad
static void showRewardVideoAd(String adId,
{AdCallback onSjmAdTradeId,
AdCallback onSjmAdLoaded,
AdCallback onSjmAdShow,
AdCallback onSjmAdReward,
AdCallback onSjmAdClick,
AdCallback onSjmAdVideoComplete,
AdCallback onSjmAdClose,
AdErrorCallback onSjmAdError}) {
EventChannel eventChannel =
EventChannel("flutter_adsjm_plugin/event_rewardVideo");
eventChannel.receiveBroadcastStream().listen((event) {
switch (event["event"]) {
case "onSjmAdTradeId":
onSjmAdTradeId?.call(event["id"]);
break;
case "onSjmAdLoaded":
onSjmAdLoaded?.call(event["id"]);
break;
case "onSjmAdShow":
onSjmAdShow?.call(event["id"]);
break;
case "onSjmAdReward":
onSjmAdReward?.call(event["id"]);
break;
case "onSjmAdClick":
onSjmAdClick?.call(event["id"]);
break;
case "onSjmAdVideoComplete":
onSjmAdVideoComplete?.call(event["id"]);
break;
case "onSjmAdClose":
onSjmAdClose?.call(event["id"]);
break;
case "onSjmAdError":
onSjmAdError?.call(event["id"], event["code"], event["message"]);
break;
}
});
_methodChannel.invokeMethod(
"showRewardVideoAd", {"_channelId": "rewardVideo", "adId": adId});
}
/// show interstitial ad
static void loadInterstitalAd(String adId,
{AdCallback onSjmAdLoaded,
AdCallback onSjmAdShow,
AdCallback onSjmAdClicked,
AdCallback onSjmAdClosed,
AdErrorCallback onSjmAdError}) {
EventChannel eventChannel =
EventChannel("flutter_adsjm_plugin/event_interstital");
eventChannel.receiveBroadcastStream().listen((event) {
switch (event["event"]) {
case "onSjmAdLoaded":
onSjmAdLoaded?.call(event["id"]);
break;
case "onSjmAdShow":
onSjmAdShow?.call(event["id"]);
break;
case "onSjmAdClicked":
onSjmAdClicked?.call(event["id"]);
break;
case "onSjmAdClosed":
onSjmAdClosed?.call(event["id"]);
break;
case "onSjmAdError":
onSjmAdError?.call(event["id"], event["code"], event["message"]);
break;
}
});
_methodChannel.invokeMethod(
"loadInterstitalAd", {"_channelId": "interstital", "adId": adId});
}
static void loadH5contentAd(
String adId, String userId, String username, String userhead,
{AdCallback onIntegralNotEnough,
AdCallback onIntegralExpend,
AdCallback onFinishTasks,
AdCallback onGameExit,
AdCallback onSjmAdRewardFinish,
AdCallback onSjmAdReward,
AdCallback onSjmAdLoaded,
AdCallback onSjmAdTradeId,
AdCallback onSjmAdClick,
AdCallback onSjmUserBehavior,
AdErrorCallback onSjmAdError}) {
EventChannel eventChannel =
EventChannel("flutter_adsjm_plugin/event_h5content");
eventChannel.receiveBroadcastStream().listen((event) {
switch (event["event"]) {
case "onIntegralNotEnough":
onIntegralNotEnough?.call(event["id"]);
break;
case "onIntegralExpend":
onIntegralExpend?.call(event["id"]);
break;
case "onFinishTasks":
onFinishTasks?.call(event["id"]);
break;
case "onGameExit":
onGameExit?.call(event["id"]);
break;
case "onSjmAdRewardFinish":
onSjmAdRewardFinish?.call(event["id"]);
break;
case "onSjmAdClick":
onSjmAdClick?.call(event["id"]);
break;
case "onSjmAdReward":
onSjmAdReward?.call(event["id"]);
break;
case "onSjmAdLoaded":
onSjmAdLoaded?.call(event["id"]);
break;
case "onSjmAdTradeId":
onSjmAdTradeId?.call(event["id"]);
break;
case "onSjmUserBehavior":
onSjmUserBehavior?.call(event["id"]);
break;
case "onSjmAdError":
onSjmAdError?.call(event["id"], event["code"], event["message"]);
break;
}
});
_methodChannel.invokeMethod("loadH5contentAd", {
"_channelId": "h5content",
"adId": adId,
"userId": userId,
"username": username,
"userhead": userhead
});
}
static void loadVideocontentAd(String adId) {
_methodChannel.invokeMethod(
"loadVideocontentAd", {"_channelId": "videocontent", "adId": adId});
}
}

View File

@@ -0,0 +1,92 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'ad.dart';
/// Widget for banner ad
class BannerAdView extends StatelessWidget {
final String adId;
final double width;
final double height;
final AdCallback onSjmAdLoaded;
final AdCallback onSjmAdShow;
final AdCallback onSjmAdClicked;
final AdCallback onSjmAdClosed;
final AdErrorCallback onSjmAdError;
BannerAdView(
{Key key,
this.adId,
this.width,
this.height,
this.onSjmAdLoaded,
this.onSjmAdShow,
this.onSjmAdClicked,
this.onSjmAdClosed,
this.onSjmAdError})
: super(key: key);
@override
Widget build(BuildContext context) {
Widget banner;
if (defaultTargetPlatform == TargetPlatform.android) {
banner = AndroidView(
viewType: 'flutter_adsjm_plugin/banner',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
banner = UiKitView(
viewType: 'flutter_adsjm_plugin/banner',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else {
banner = Text("Not supported");
}
return Container(
width: width,
height: height,
child: banner,
);
}
void _onPlatformViewCreated(int id) {
EventChannel eventChannel = EventChannel("flutter_adsjm_plugin/banner_event_$id");
eventChannel.receiveBroadcastStream().listen((event) {
switch (event["event"]) {
case "onSjmAdLoaded":
onSjmAdLoaded?.call(event["id"]);
break;
case "onSjmAdShow":
onSjmAdShow?.call(event["id"]);
break;
case "onSjmAdClicked":
onSjmAdClicked?.call(event["id"]);
break;
case "onSjmAdClosed":
onSjmAdClosed?.call(event["id"]);
break;
case "onSjmAdError":
onSjmAdError?.call(event["id"], event["code"], event["message"]);
break;
}
});
}
}

View File

@@ -0,0 +1,92 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'ad.dart';
/// Widget for banner ad
class NativeExpressAdView extends StatelessWidget {
final String adId;
final double width;
final double height;
final AdCallback onSjmAdLoaded;
final AdCallback onSjmAdShow;
final AdCallback onSjmAdClicked;
final AdCallback onSjmAdClosed;
final AdErrorCallback onSjmAdError;
NativeExpressAdView(
{Key key,
this.adId,
this.width,
this.height,
this.onSjmAdLoaded,
this.onSjmAdShow,
this.onSjmAdClicked,
this.onSjmAdClosed,
this.onSjmAdError})
: super(key: key);
@override
Widget build(BuildContext context) {
Widget banner;
if (defaultTargetPlatform == TargetPlatform.android) {
banner = AndroidView(
viewType: 'flutter_adsjm_plugin/native_express',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
banner = UiKitView(
viewType: 'flutter_adsjm_plugin/native_express',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else {
banner = Text("Not supported");
}
return Container(
width: width,
height: height,
child: banner,
);
}
void _onPlatformViewCreated(int id) {
EventChannel eventChannel = EventChannel("flutter_adsjm_plugin/native_express_event_$id");
eventChannel.receiveBroadcastStream().listen((event) {
switch (event["event"]) {
case "onSjmAdLoaded":
onSjmAdLoaded?.call(event["id"]);
break;
case "onSjmAdShow":
onSjmAdShow?.call(event["id"]);
break;
case "onSjmAdClicked":
onSjmAdClicked?.call(event["id"]);
break;
case "onSjmAdClosed":
onSjmAdClosed?.call(event["id"]);
break;
case "onSjmAdError":
onSjmAdError?.call(event["id"], event["code"], event["message"]);
break;
}
});
}
}

View File

@@ -0,0 +1,93 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'ad.dart';
/// Widget for splash ad
class SplashAdView extends StatelessWidget {
final String adId;
final double width;
final double height;
final AdCallback onSjmAdLoaded;
final AdCallback onSjmAdShow;
final AdCallback onSjmAdClicked;
final AdCallback onSjmAdClosed;
final AdErrorCallback onSjmAdError;
SplashAdView(
{Key key,
this.adId,
this.width,
this.height,
this.onSjmAdLoaded,
this.onSjmAdShow,
this.onSjmAdClicked,
this.onSjmAdClosed,
this.onSjmAdError})
: super(key: key);
@override
Widget build(BuildContext context) {
Widget splash;
if (defaultTargetPlatform == TargetPlatform.android) {
splash = AndroidView(
viewType: 'flutter_adsjm_plugin/splash',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
splash = UiKitView(
viewType: 'flutter_adsjm_plugin/splash',
creationParams: {
"adId": adId,
"width": width,
"height": height,
},
creationParamsCodec: const StandardMessageCodec(),
onPlatformViewCreated: _onPlatformViewCreated,
);
} else {
splash = Text("Not supported");
}
return Container(
width: width,
height: height,
child: splash,
);
}
void _onPlatformViewCreated(int id) {
EventChannel eventChannel =
EventChannel("flutter_adsjm_plugin/splash_event_$id");
eventChannel.receiveBroadcastStream().listen((event) {
switch (event["event"]) {
case "onSjmAdLoaded":
onSjmAdLoaded?.call(event["id"]);
break;
case "onSjmAdShow":
onSjmAdShow?.call(event["id"]);
break;
case "onSjmAdClicked":
onSjmAdClicked?.call(event["id"]);
break;
case "onSjmAdClosed":
onSjmAdClosed?.call(event["id"]);
break;
case "onSjmAdError":
onSjmAdError?.call(event["id"], event["code"], event["message"]);
break;
}
});
}
}

View File

@@ -1,22 +0,0 @@
import 'dart:convert';
import 'package:http/http.dart' as Http;
class HttpApi {
final String BaseApi = 'http://api.gl.shangkelian.cn/api/';
/// post
ApiPost(String api, {Map? body}) async {
String apiUrl = BaseApi + api;
var url = Uri.parse(apiUrl);
var response = await Http.post(url, body: body);
int newCode = response.statusCode;
Map data = jsonDecode(response.body);
if (newCode == 200) {
print('请求成功返回值$data');
return data;
}
// print(apiUrl);
// print('可选参数${body}');
}
}

7
lib/https/config.dart Normal file
View File

@@ -0,0 +1,7 @@
class HttpConfig {
static const bool isDebug = false;
static const bool offSsl = false;
static const String baseUrl = 'http://api.zh.shangkelian.cn/api/';
static const int connectTimeout = 5000;
static const int receiveTimeout = 5000;
}

14
lib/https/http.dart Normal file
View File

@@ -0,0 +1,14 @@
import 'package:dio/dio.dart';
import 'config.dart';
class HttpApi {
static HttpApi? instance;
HttpApi() {
print('回家啊哈哈');
}
}
void main() {
HttpApi();
}

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'pages/tabs/tabs.dart';
import 'pages/auth/auth.dart';
// import 'pages/auth/auth.dart';
void main() {
runApp(

View File

@@ -12,11 +12,26 @@ class _DtxPagesState extends State<DtxPages> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('DTX积分'),
title: const Text(
'DT积分',
style: TextStyle(
fontSize: 15.0,
),
),
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
foregroundColor: Colors.black,
),
body: const Center(
child: Text('Dtx积分'),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const <Widget>[
Text('DTX行情'),
Text('个人资产信息'),
Text('DT积分管理'),
Text('行情交易走势'),
Text('DTX交易走势图'),
Text('DTX落槌量走势图'),
],
),
);
}

View File

@@ -1,8 +1,6 @@
import 'package:flutter/material.dart';
import '../auth/auth.dart';
import '../../https/auth_api.dart';
class StorePages extends StatefulWidget {
const StorePages({Key? key}) : super(key: key);
@@ -13,13 +11,14 @@ class StorePages extends StatefulWidget {
class _StorePagesState extends State<StorePages> {
@override
void initState() {
HttpApi().ApiPost(
'user/auth/sms',
body: {
'mobileNo': '18245180131',
'code': '0000',
},
);
// print('初始化');
// HttpApi().ApiPost(
// 'user/auth/sms',
// body: {
// 'mobileNo': '18245180131',
// 'code': '0000',
// },
// );
super.initState();
}

View File

@@ -1,5 +1,9 @@
import 'package:flutter/material.dart';
/// widget
import './widget/user_info.dart';
import './widget/user_order.dart';
class UserPages extends StatefulWidget {
const UserPages({Key? key}) : super(key: key);
@@ -11,12 +15,14 @@ class _UserPagesState extends State<UserPages> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('我的'),
shadowColor: Colors.transparent,
),
body: const Center(
child: Text('我的'),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const <Widget>[
UserInfo(),
UserOrder(),
],
),
),
);
}

View File

@@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
class UserInfo extends StatefulWidget {
const UserInfo({Key? key}) : super(key: key);
@override
State<UserInfo> createState() => _UserInfoState();
}
class _UserInfoState extends State<UserInfo> {
@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
padding: EdgeInsets.fromLTRB(
20.0,
MediaQuery.of(context).padding.top,
20.0,
50.0,
),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/login/auth_bg.png'),
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const SizedBox(height: 40.0),
ClipOval(
child: Image.network(
'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fedpic%2F78%2Fab%2Ffc%2F78abfc26e04035fc8fd68aaee233c5b7.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1656234411&t=4544b17883f935447981f761b1e2a941',
height: 65.0,
width: 65.0,
),
),
const SizedBox(height: 15.0),
const Text(
'唐明明',
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 5.0),
const Text(
'NTF编号00001',
style: TextStyle(
color: Colors.white,
),
),
],
),
);
}
}

View File

@@ -0,0 +1,93 @@
import 'package:flutter/material.dart';
import '../../../main_color.dart';
class UserOrder extends StatelessWidget {
const UserOrder({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'订单管理',
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10.0),
Card(
child: Row(children: <Widget>[
Expanded(
flex: 1,
child: Column(children: const <Widget>[
Icon(Icons.home),
Text(
'全部',
style: TextStyle(fontSize: 12.0, color: tTextColor),
textAlign: TextAlign.center,
)
]),
),
Expanded(
flex: 1,
child: Column(children: <Widget>[
Image.asset(
'assets/icons/order_icon_00.png',
width: 20.0,
fit: BoxFit.fitWidth,
),
const SizedBox(height: 5.0),
const Text(
'待支付',
style: TextStyle(fontSize: 12.0, color: tTextColor),
textAlign: TextAlign.center,
)
]),
),
Expanded(
flex: 1,
child: Column(children: const <Widget>[
Icon(Icons.card_giftcard),
Text(
'待发货',
style: TextStyle(fontSize: 12.0, color: tTextColor),
textAlign: TextAlign.center,
)
]),
),
Expanded(
flex: 1,
child: Column(children: const <Widget>[
Icon(Icons.check),
Text(
'待收货',
style: TextStyle(fontSize: 12.0, color: tTextColor),
textAlign: TextAlign.center,
)
]),
),
Expanded(
flex: 1,
child: Column(children: const <Widget>[
SizedBox(height: 15.0),
Icon(Icons.home),
Text(
'已完成',
style: TextStyle(fontSize: 12.0, color: tTextColor),
textAlign: TextAlign.center,
),
SizedBox(height: 15.0),
]),
),
]),
)
],
),
);
}
}