import
'package:flutter/material.dart'
;
import
'package:flutter/services.dart'
;
import
'package:get_mac/get_mac.dart'
;
void
main() {
runApp(
const
MyApp());
}
class
MyApp extends StatelessWidget {
const
MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return
MaterialApp(
title:
'MAC Finder'
,
theme: ThemeData(
primarySwatch: Colors.green,
),
home:
const
Home(),
);
}
}
class
Home extends StatefulWidget {
const
Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class
_HomeState extends State<Home> {
String _deviceMAC =
'Click the button.'
;
Future<
void
> initMacAddress() async {
String macAddress;
try
{
macAddress = await GetMac.macAddress;
} on PlatformException {
macAddress =
'Error getting the MAC address.'
;
}
setState(() {
_deviceMAC = macAddress;
});
}
@override
Widget build(BuildContext context) {
return
Scaffold(
appBar: AppBar(
title:
const
Text(
'MAC address of a device'
),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
_deviceMAC,
style:
const
TextStyle(fontSize: 26, fontWeight: FontWeight.bold),
),
ElevatedButton(
onPressed: () {
initMacAddress();
},
child:
const
Text(
"Get MAC Address"
),
),
],
),
),
);
}
}