aliyun_httpdns 2.0.0 copy "aliyun_httpdns: ^2.0.0" to clipboard
aliyun_httpdns: ^2.0.0 copied to clipboard

Aliyun HTTPDNS Flutter SDK - Pure Dart implementation for DNS resolution service.

example/example.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'HTTPDNS Example',
      home: const HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String _result = '';

  @override
  void initState() {
    super.initState();
    _initHttpdns();
  }

  Future<void> _initHttpdns() async {
    final config = AliyunHttpdnsConfig(
      accountId: 0, // 替换为您的 AccountId
      secretKey: 'YOUR_SECRET_KEY', // 替换为您的 SecretKey(可选)
    );
    await AliyunHttpdns.init(config);
    AliyunHttpdns.setLogEnabled(true);
    await AliyunHttpdns.setPreResolveHosts(['www.aliyun.com']);
  }

  Future<void> _resolve() async {
    final result = await AliyunHttpdns.resolveHostSyncNonBlocking(
      'www.aliyun.com',
      ipType: HttpdnsIpType.auto,
    );
    setState(() {
      if (result != null) {
        _result = 'IPv4: ${result.ips}\nIPv6: ${result.ipv6s}';
      } else {
        _result = '解析结果为空';
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('HTTPDNS Example')),
      body: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            ElevatedButton(
              onPressed: _resolve,
              child: const Text('解析 www.aliyun.com'),
            ),
            const SizedBox(height: 16),
            Text(_result),
          ],
        ),
      ),
    );
  }
}
2
likes
135
points
344
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Aliyun HTTPDNS Flutter SDK - Pure Dart implementation for DNS resolution service.

Homepage

License

MIT (license)

Dependencies

connectivity_plus, crypto, encrypt, flutter, hive, hive_flutter

More

Packages that depend on aliyun_httpdns