Flutter插件potator的使用方法
Flutter插件potator的使用方法
Flutter插件potator的使用
-
安装potator:
flutter pub add potator
-
导入包:
import 'package:potator/potator.dart';
-
使用它:
Potator potator = Potator('YOUR_POTATO_SERVER_URL'); // 如果你不想更改服务器,可以不包含 `'YOUR_POTATO_SERVER_URL'` potator.use('YOUR_POTATO_SERVER_URL'); // 可选,更改土豆服务器 final String google = await potator.get('google.potato/'); // 斜杠是可选的,可用于获取特定文件,例如: final String hosts = await potator.get('hosts.potato/HOSTS.txt'); // 将返回官方HOSTS列表
完整示例Demo
import 'package:flutter/material.dart';
import 'package:potator/potator.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Potator Example (DOESNT DISPLAY WEB)'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
[@override](/user/override)
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String? hosts;
[@override](/user/override)
void initState() {
super.initState();
getHosts();
}
void getHosts() async {
Potator potator = Potator();
final response = await potator.get('hosts.potato/HOSTS.txt');
setState(() {
hosts = response;
});
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
hosts ?? 'Loading the official hosts...',
)
],
),
),
);
}
}
更多关于Flutter插件potator的使用方法的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复