mdns_plugin 0.0.5 copy "mdns_plugin: ^0.0.5" to clipboard
mdns_plugin: ^0.0.5 copied to clipboard

outdated

mDNS Service discovery plugin for iOS which generates events whenever service discovery is started or stopped, or whenever new services on the network are found, removed or updated.

example/lib/main.dart

/*
  mDNS Plugin Example
  Flutter client demonstrating browsing for Chromecasts
  on your local network

  Copyright (c) David Thorpe 2019
  Please see the LICENSE file for licensing information
*/

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import 'package:mdns_plugin/mdns_plugin.dart';
import 'package:mdns_plugin_example/src/pages/service_list.dart';
import 'package:mdns_plugin_example/src/bloc/app.dart';

/////////////////////////////////////////////////////////////////////

void main() {
  runApp(BlocProvider<AppBloc>(
      builder: (context) {
        return AppBloc()..dispatch(AppEventStart());
      },
      child: MyApp()));
}

/////////////////////////////////////////////////////////////////////

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  // CONSTRUCTORS ///////////////////////////////////////////////////

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

  // METHODS ////////////////////////////////////////////////////////

  Future<void> initPlatformState() async {
    String platformVersion;

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await MDNSPlugin.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: AppBar(
              title: const Text('Chromecast Browser'),
            ),
            body: BlocBuilder<AppBloc, AppState>(builder: (context, state) {
              if (state is AppStateUninitialized) {
                return Placeholder();
              } else {
                return ServiceList();
              }
            })));
  }
}
8
likes
0
pub points
31%
popularity

Publisher

verified publishermutablelogic.com

mDNS Service discovery plugin for iOS which generates events whenever service discovery is started or stopped, or whenever new services on the network are found, removed or updated.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on mdns_plugin