pihole_api 0.3.1 copy "pihole_api: ^0.3.1" to clipboard
pihole_api: ^0.3.1 copied to clipboard

Provides models and endpoint wrappers for the Pi-hole API (summary, queries, versions etc.).

example/lib/main.dart

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:pihole_api/pihole_api.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Pi-hole API Demo',
      home: PiholeApiDemo(),
    );
  }
}

class PiholeApiDemo extends StatefulWidget {
  const PiholeApiDemo({Key? key}) : super(key: key);

  static final pihole = PiholeApiDio(
      params: PiholeApiParams(
    baseUrl: "http://192.168.2.24",
    apiPath: "/admin/api.php",
    apiTokenRequired: true,
    // Find the API token from your Pi-hole admin dashboard while signed in,
    // e.g. from http://pi.hole/admin/scripts/pi-hole/php/api_token.php.
    apiToken: const String.fromEnvironment(
      "PIHOLE_API_TOKEN",
      defaultValue: "MY_TOKEN",
    ),
    allowSelfSignedCertificates: false,
    adminHome: "/admin",
  ));

  @override
  State<PiholeApiDemo> createState() => _PiholeApiDemoState();
}

class _PiholeApiDemoState extends State<PiholeApiDemo> {
  Future<PiSummary> summary = PiholeApiDemo.pihole.fetchSummary(CancelToken());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Pi-hole API Demo'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(
              onPressed: () {
                setState(() {
                  summary = PiholeApiDemo.pihole.fetchSummary(CancelToken());
                });
              },
              child: const Text('Refresh summary')),
          FutureBuilder(
              future: summary,
              builder: (context, snapshot) {
                return Padding(
                  padding: const EdgeInsets.all(24.0),
                  child: Card(
                      child: Padding(
                    padding: const EdgeInsets.all(24.0),
                    child: Text(snapshot.toString()),
                  )),
                );
              }),
        ],
      ),
    );
  }
}
0
likes
110
pub points
0%
popularity

Publisher

verified publishertster.nl

Provides models and endpoint wrappers for the Pi-hole API (summary, queries, versions etc.).

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

clock, dio, freezed_annotation, html, http_mock_adapter, json_annotation

More

Packages that depend on pihole_api