|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_design/constant/string_const.dart'; |
| 3 | +import 'package:flutter_design/page/command/command_mode.dart'; |
| 4 | + |
| 5 | +/// Created by NieBin on 2020-03-31 |
| 6 | +/// Github: https://github.com/nb312 |
| 7 | +/// Email: niebin312@gmail.com |
| 8 | +
|
| 9 | +class CommandPage extends StatefulWidget { |
| 10 | + @override |
| 11 | + _CommandPageState createState() => _CommandPageState(); |
| 12 | +} |
| 13 | + |
| 14 | +class _CommandPageState extends State<CommandPage> { |
| 15 | + AudioPlayer _player; |
| 16 | + |
| 17 | + @override |
| 18 | + initState() { |
| 19 | + super.initState(); |
| 20 | + _player = AudioPlayer(); |
| 21 | + } |
| 22 | + |
| 23 | + @override |
| 24 | + Widget build(BuildContext context) { |
| 25 | + return Scaffold( |
| 26 | + appBar: AppBar( |
| 27 | + title: Text(StringConst.COMMAND_), |
| 28 | + ), |
| 29 | + body: Container( |
| 30 | + alignment: Alignment.center, |
| 31 | + child: Row( |
| 32 | + crossAxisAlignment: CrossAxisAlignment.center, |
| 33 | + mainAxisAlignment: MainAxisAlignment.center, |
| 34 | + children: <Widget>[ |
| 35 | + _button( |
| 36 | + icon: Icons.pause, |
| 37 | + callback: () { |
| 38 | + PointerInvoker invoker = PointerInvoker(); |
| 39 | + invoker.command = PauseCommand(_player); |
| 40 | + invoker.execute(); |
| 41 | + }, |
| 42 | + color: Colors.red), |
| 43 | + _button( |
| 44 | + icon: Icons.stop, |
| 45 | + callback: () { |
| 46 | + PointerInvoker invoker = PointerInvoker(); |
| 47 | + invoker.command = StopCommand(_player); |
| 48 | + invoker.execute(); |
| 49 | + }, |
| 50 | + color: Colors.red), |
| 51 | + _button( |
| 52 | + icon: Icons.play_arrow, |
| 53 | + callback: () { |
| 54 | + PointerInvoker invoker = PointerInvoker(); |
| 55 | + invoker.command = PlayCommand(_player); |
| 56 | + invoker.execute(); |
| 57 | + }, |
| 58 | + color: Colors.red), |
| 59 | + _button( |
| 60 | + icon: Icons.skip_next, |
| 61 | + callback: () { |
| 62 | + PointerInvoker invoker = PointerInvoker(); |
| 63 | + invoker.command = NextCommand(_player); |
| 64 | + invoker.execute(); |
| 65 | + }, |
| 66 | + color: Colors.green), |
| 67 | + ], |
| 68 | + ), |
| 69 | + ), |
| 70 | + ); |
| 71 | + } |
| 72 | + |
| 73 | + Widget _button({ |
| 74 | + IconData icon, |
| 75 | + VoidCallback callback, |
| 76 | + Color color = Colors.white, |
| 77 | + }) => |
| 78 | + FlatButton( |
| 79 | + color: color, |
| 80 | + child: Padding( |
| 81 | + padding: const EdgeInsets.all(10.0), |
| 82 | + child: Icon( |
| 83 | + icon, |
| 84 | + size: 30, |
| 85 | + ), |
| 86 | + ), |
| 87 | + onPressed: callback, |
| 88 | + shape: CircleBorder(), |
| 89 | + ); |
| 90 | +} |
0 commit comments