Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- Flutter Example
- node.js
- WillPopScope
- Flutter 예제
- Flutter 앱 배포
- Flutter 강좌
- Snackbar
- 반석천
- AppBar
- ListView.builder
- Hello World
- Column Widget
- Load Image
- Image.network
- CrossAxisAlignment
- Flutter Tutorial
- Row Widget
- MainAxisAlignment
- Cached Image
- Scaffold
- navigator
- Row
- sqlite
- ListTile
- HTTP
- Networking
- listview
- InkWell
- flutter
- FutureBuilder
Archives
- Today
- Total
꿈꾸는 시스템 디자이너
Flutter Example - How to set the volume | volume plugin 본문
Tutorial/Flutter with App
Flutter Example - How to set the volume | volume plugin
독행소년 2020. 3. 23. 12:38
* About plugin
https://pub.dev/packages/volume
1. Add this to pubspec.yaml
dependencies:
volume: ^0.1.0
2. Source Code
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:volume/volume.dart';
void main() => runApp(VolumePage());
class VolumePage extends StatefulWidget {
@override
_VolumePageState createState() => _VolumePageState();
}
class _VolumePageState extends State<VolumePage> {
AudioManager audioManager;
int maxVol, currentVol;
@override
void initState() {
super.initState();
audioManager = AudioManager.STREAM_SYSTEM;
initPlatformState(AudioManager.STREAM_VOICE_CALL);
updateVolumes();
}
Future<void> initPlatformState(AudioManager am) async {
await Volume.controlVolume(am);
}
void updateVolumes() async {
// get Max Volume
maxVol = await Volume.getMaxVol;
// get Current Volume
currentVol = await Volume.getVol;
print("maxVol: $maxVol, currentVol: $currentVol");
setState(() {});
}
void setVol(int i) async {
await Volume.setVol(i);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Volume Plugin example app'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text("Max Volume: $maxVol"),
Text("Current Volume: $currentVol")
],
),
),
DropdownButton(
value: audioManager,
items: [
DropdownMenuItem(
child: Text("In Call Volume"),
value: AudioManager.STREAM_VOICE_CALL,
),
DropdownMenuItem(
child: Text("System Volume"),
value: AudioManager.STREAM_SYSTEM,
),
DropdownMenuItem(
child: Text("Ring Volume"),
value: AudioManager.STREAM_RING,
),
DropdownMenuItem(
child: Text("Media Volume"),
value: AudioManager.STREAM_MUSIC,
),
DropdownMenuItem(
child: Text("Alarm volume"),
value: AudioManager.STREAM_ALARM,
),
DropdownMenuItem(
child: Text("Notifications Volume"),
value: AudioManager.STREAM_NOTIFICATION,
),
],
isDense: true,
onChanged: (AudioManager am) async {
print(am.toString());
initPlatformState(am);
updateVolumes();
},
),
(currentVol != null || maxVol != null)
? Slider(
value: currentVol / 1.0,
divisions: maxVol,
max: maxVol / 1.0,
min: 0,
onChanged: (double d) {
setVol(d.toInt());
updateVolumes();
},
)
: Container(),
],
),
),
),
);
}
}
'Tutorial > Flutter with App' 카테고리의 다른 글
Flutter Example - TCP Socket Server (0) | 2020.04.14 |
---|---|
Flutter Example - ListView | Handle Items | Change items (0) | 2020.03.24 |
Flutter Example - How to add Admob Ad in Flutter App | firebase_admob plugin (0) | 2019.10.31 |
Flutter Example - Http Request | Get method | http plugin (0) | 2019.10.23 |
Flutter Example - Launch Web Browser | url_launcher plugin (0) | 2019.10.23 |
Comments