ad_link_plugin 1.0.0
ad_link_plugin: ^1.0.0 copied to clipboard
Flutter Link Plugin for Android.
example/lib/main.dart
import 'package:ad_link_plugin/ad_link_webview.dart';
import 'package:flutter/material.dart';
import 'web_view_page.dart';
import 'api_demo.dart'; // 新增导入
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: mNavigatorKey,
title: 'Link Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Link Flutter Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
// setNamespace
AdLinkWebView.setNamespace("oks");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Column(
children: [
Column(
children: [
const SizedBox(height: 16),
// New Activity
AppButton(
onPressed: () {
String linkUrl = 'https://s.gamifyspace.com/tml?pid=8765&appk=mCM3hsh5AnS5jJumFicKqDmiNaZaQfvs&did=f5bb825f-a1b8-44f8-a24d-10ca1ad1abe1';
AdLinkWebView.open('8765', linkUrl);
},
text: 'New Link Activity',
),
const SizedBox(height: 16),
AppButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
String linkUrl = 'https://s.gamifyspace.com/tml?pid=8765&appk=mCM3hsh5AnS5jJumFicKqDmiNaZaQfvs&did=f5bb825f-a1b8-44f8-a24d-10ca1ad1abe1';
return AdLinkWebViewPage(pid: '8765', link: linkUrl);
}),
);
},
text: 'New Link WebView',
),
],
),
],
),
// 添加悬浮按钮
floatingActionButton: RawMaterialButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const WebViewInjector()), // 跳转到 api_demo.dart 的 MyApp 页面
);
},
elevation: 0, // 去除阴影
// foregroundColor: Colors.transparent, // 背景透明
// backgroundColor: Colors.transparent, // 背景透明
fillColor: Colors.transparent,
constraints: const BoxConstraints.tightFor(
width: 80,
height: 80,
),
child: Image.asset(
'assets/float_icon.gif',
width: 80,
height: 80,
fit: BoxFit.contain, // 推荐加上
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat, // 位置调整
);
}
}
class AppButton extends StatelessWidget {
final String text;
final VoidCallback? onPressed; // Nullable onPressed
const AppButton({
super.key,
required this.text,
this.onPressed, // Optional onPressed
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(left: 40, right: 40),
child: SizedBox(
height: 36, // Set button height
child: ElevatedButton(
onPressed: onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.grey[200],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8), // Custom border radius
),
),
child: Text(
text,
style: const TextStyle(
fontSize: 18, // Set text font size to 18
color: Colors.black,
),
),
),
),
);
}
}