flutter_p2p_connection 3.0.0
flutter_p2p_connection: ^3.0.0 copied to clipboard
A WiFi Direct Plugin for Flutter. This Plugin uses the native WiFi P2P API of Android.
import 'package:flutter/material.dart';
import 'package:flutter_p2p_connection_example/client.dart';
import 'package:flutter_p2p_connection_example/host.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter p2p connection plugin'),
),
body: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// host
const SizedBox(height: 30),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const HostPage(),
),
);
},
child: Container(
height: 150,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blue,
),
child: const Center(
child: Text(
'HOST',
style: TextStyle(
fontWeight: FontWeight.w800,
fontSize: 30,
),
),
),
),
),
// client
const SizedBox(height: 30),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ClientPage(),
),
);
},
child: Container(
height: 150,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.red,
),
child: const Center(
child: Text(
'CLIENT',
style: TextStyle(
fontWeight: FontWeight.w800,
fontSize: 30,
),
),
),
),
),
],
),
),
);
}
}