lecle_system_shortcuts 0.0.1 lecle_system_shortcuts: ^0.0.1 copied to clipboard
A flutter plugin to use the Android and iOS system shortcuts.
import 'package:flutter/material.dart';
import 'package:lecle_system_shortcuts/lecle_system_shortcuts.dart';
void main() => runApp(const Main());
class Main extends StatelessWidget {
const Main({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('System Shortcuts'),
),
body: const PreviousPage(),
),
);
}
}
class PreviousPage extends StatefulWidget {
const PreviousPage({Key? key}) : super(key: key);
@override
_PreviousPageState createState() => _PreviousPageState();
}
class _PreviousPageState extends State<PreviousPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Previous screen'),
const SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => const MyApp(),
),
);
},
child: const Text('Open MyApp page'),
)
],
),
),
);
}
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('System Shortcuts'),
),
body: Center(
child: ListView(
physics: const ClampingScrollPhysics(),
children: <Widget>[
TextButton(
child: const Text("Home"),
onPressed: () async {
await SystemShortcuts.home();
},
),
TextButton(
child: const Text("Back"),
onPressed: () async {
await SystemShortcuts.back();
},
),
TextButton(
child: const Text("VolDown"),
onPressed: () async {
await SystemShortcuts.volDown(
streamType: AudioManger.streamAlarm,
showVolumeUiFlag: true);
},
),
TextButton(
child: const Text("VolUp"),
onPressed: () async {
await SystemShortcuts.volUp(
streamType: AudioManger.streamAlarm,
showVolumeUiFlag: true);
},
),
TextButton(
child: const Text("Landscape"),
onPressed: () async {
await SystemShortcuts.orientLandscape();
},
),
TextButton(
child: const Text("Portrait"),
onPressed: () async {
await SystemShortcuts.orientPortrait();
},
),
TextButton(
child: const Text("Wifi"),
onPressed: () async {
await SystemShortcuts.wifi();
},
),
TextButton(
child: const Text("Check Wifi"),
onPressed: () async {
bool? b = await SystemShortcuts.checkWifi;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Wifi Turned On Check - $b"),
duration: const Duration(seconds: 2),
),
);
},
),
TextButton(
child: const Text("Bluetooth"),
onPressed: () async {
await SystemShortcuts.bluetooth();
},
),
TextButton(
child: const Text("Check Bluetooth"),
onPressed: () async {
bool? b = await SystemShortcuts.checkBluetooth;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Bluetooth Turned On Check - $b"),
duration: const Duration(seconds: 2),
),
);
},
),
],
),
),
);
}
}