openlp-mobile-remote/lib/src/widgets/display_options_dialog.dart

109 lines
3.8 KiB
Dart

// OpenLP Mobile Remote
// ---------------------------------------------------------------------------
// Copyright (c) 2008-2019 OpenLP Developers
// ---------------------------------------------------------------------------
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../bloc/display_options_dialog_bloc.dart';
import '../configurations/app_localizations.dart';
class _Action {
String titleKey;
Function(DisplayOptionsDialogBloc) callback;
_Action({@required this.titleKey, @required this.callback});
}
class DisplayOptionsDialog extends StatelessWidget {
final List<_Action> _actions = [
_Action(
titleKey: 'display_option_blank',
callback: (bloc) {
bloc.setBlankScreen();
},
),
_Action(
titleKey: 'display_option_theme',
callback: (bloc) {
bloc.setThemeScreen();
},
),
_Action(
titleKey: 'display_option_desktop',
callback: (bloc) {
bloc.setDesktopScreen();
},
),
_Action(
titleKey: 'display_option_show',
callback: (bloc) {
bloc.setFullProjection();
},
),
];
final GlobalKey<ScaffoldState> _scaffoldKey;
DisplayOptionsDialog(this._scaffoldKey);
@override
Widget build(BuildContext context) {
final bloc = BlocProvider.of<DisplayOptionsDialogBloc>(context);
return BlocListener<DisplayOptionsDialogBloc, DisplayOptionsState>(
bloc: bloc,
condition: (previous, current) => current != DisplayOptionsState.waiting,
listener: (context, state) {
String text;
Color backgroundColor;
switch (state) {
case DisplayOptionsState.success:
text = AppLocalizations.of(context).translate('success');
break;
case DisplayOptionsState.failure:
text = AppLocalizations.of(context).translate('failure');
backgroundColor = Colors.red;
break;
default:
break;
}
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(text),
backgroundColor: backgroundColor,
));
},
child: SimpleDialog(
contentPadding: EdgeInsets.all(20.0),
children: _actions
.map((action) => OutlineButton(
borderSide: BorderSide(color: Theme.of(context).primaryColor),
textColor: Theme.of(context).primaryColor,
child: Text(
AppLocalizations.of(context).translate(action.titleKey)),
onPressed: () {
action.callback(bloc);
Navigator.of(context).pop();
},
))
.toList(),
),
);
}
}