display options API integration

This commit is contained in:
Daniel Borges 2019-08-20 18:10:17 -03:00
parent 419302a77b
commit f7718140e6
7 changed files with 43 additions and 25 deletions

View File

@ -40,5 +40,7 @@
"dialog_server_ip_title": "Type the IP", "dialog_server_ip_title": "Type the IP",
"dialog_server_port_title": "Type the port", "dialog_server_port_title": "Type the port",
"dialog_server_user_id_title": "Type the ID", "dialog_server_user_id_title": "Type the ID",
"dialog_server_user_pass_title": "Type the password" "dialog_server_user_pass_title": "Type the password",
"success": "Success",
"failure": "Failure"
} }

View File

@ -24,14 +24,23 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
import 'src/bloc/display_options_dialog_bloc.dart';
import 'src/bloc/settings_bloc.dart'; import 'src/bloc/settings_bloc.dart';
import 'src/openlp_mobile_remote_app.dart'; import 'src/openlp_mobile_remote_app.dart';
import 'src/configurations/app_theme.dart'; import 'src/configurations/app_theme.dart';
import 'src/configurations/app_localizations.dart'; import 'src/configurations/app_localizations.dart';
import 'src/screens/settings.dart'; import 'src/screens/settings.dart';
void main() => runApp( void main() => runApp(MultiBlocProvider(
MaterialApp( providers: [
BlocProvider<DisplayOptionsDialogBloc>(
builder: (context) => DisplayOptionsDialogBloc(),
),
BlocProvider<SettingsBloc>(
builder: (context) => SettingsBloc(),
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
theme: appTheme, theme: appTheme,
supportedLocales: [ supportedLocales: [
@ -62,10 +71,7 @@ void main() => runApp(
}, },
routes: <String, WidgetBuilder>{ routes: <String, WidgetBuilder>{
'/': (context) => OpenLPMobileRemoteApp(), '/': (context) => OpenLPMobileRemoteApp(),
'/settings': (context) => BlocProvider( '/settings': (context) => Settings(),
builder: (context) => SettingsBloc(),
child: Settings(),
),
}, },
), ),
); ));

View File

@ -26,7 +26,7 @@ import 'package:meta/meta.dart';
import '../network/api.dart' as api; import '../network/api.dart' as api;
enum DisplayOptionsState { none, success, failure } enum DisplayOptionsState { waiting, success, failure }
@immutable @immutable
abstract class SetDisplayTypeEvent extends Equatable { abstract class SetDisplayTypeEvent extends Equatable {
@ -54,7 +54,7 @@ class SetDisplayTypeShowEvent extends SetDisplayTypeEvent {
class DisplayOptionsDialogBloc class DisplayOptionsDialogBloc
extends Bloc<SetDisplayTypeEvent, DisplayOptionsState> { extends Bloc<SetDisplayTypeEvent, DisplayOptionsState> {
@override @override
DisplayOptionsState get initialState => DisplayOptionsState.none; DisplayOptionsState get initialState => DisplayOptionsState.waiting;
void setBlankScreen() { void setBlankScreen() {
dispatch(SetDisplayTypeBlankEvent()); dispatch(SetDisplayTypeBlankEvent());
@ -81,6 +81,6 @@ class DisplayOptionsDialogBloc
} catch (e) { } catch (e) {
yield DisplayOptionsState.failure; yield DisplayOptionsState.failure;
} }
yield DisplayOptionsState.none; yield DisplayOptionsState.waiting;
} }
} }

View File

@ -36,6 +36,7 @@ class OpenLPMobileRemoteApp extends StatefulWidget {
class _OpenLPMobileRemoteAppState extends State<OpenLPMobileRemoteApp> class _OpenLPMobileRemoteAppState extends State<OpenLPMobileRemoteApp>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
TabController tabController; TabController tabController;
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
@override @override
void initState() { void initState() {
@ -46,6 +47,7 @@ class _OpenLPMobileRemoteAppState extends State<OpenLPMobileRemoteApp>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
key: _scaffoldKey,
appBar: AppBar( appBar: AppBar(
title: Text('OpenLP Remote'), title: Text('OpenLP Remote'),
actions: <Widget>[ actions: <Widget>[
@ -74,7 +76,7 @@ class _OpenLPMobileRemoteAppState extends State<OpenLPMobileRemoteApp>
), ),
floatingActionButton: SearchFloatingButton(), floatingActionButton: SearchFloatingButton(),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: AppBottomNavigationBar(), bottomNavigationBar: AppBottomNavigationBar(_scaffoldKey),
); );
} }
} }

View File

@ -35,6 +35,10 @@ class _Action {
} }
class AppBottomNavigationBar extends StatelessWidget { class AppBottomNavigationBar extends StatelessWidget {
final GlobalKey<ScaffoldState> _scaffoldKey;
AppBottomNavigationBar(this._scaffoldKey);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<_Action> _actions = [ final List<_Action> _actions = [
@ -54,7 +58,7 @@ class AppBottomNavigationBar extends StatelessWidget {
() { () {
showDialog( showDialog(
context: context, context: context,
builder: (context) => DisplayOptionsDialog(), builder: (context) => DisplayOptionsDialog(_scaffoldKey),
); );
}, },
), ),

View File

@ -59,30 +59,34 @@ class DisplayOptionsDialog extends StatelessWidget {
}, },
), ),
]; ];
final GlobalKey<ScaffoldState> _scaffoldKey;
DisplayOptionsDialog(this._scaffoldKey);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bloc = DisplayOptionsDialogBloc(); final bloc = BlocProvider.of<DisplayOptionsDialogBloc>(context);
return BlocListener<DisplayOptionsDialogBloc, DisplayOptionsState>( return BlocListener<DisplayOptionsDialogBloc, DisplayOptionsState>(
bloc: bloc, bloc: bloc,
condition: (previous, current) => current != DisplayOptionsState.none, condition: (previous, current) => current != DisplayOptionsState.waiting,
listener: (context, state) { listener: (context, state) {
print(state); String text;
Color backgroundColor;
switch (state) { switch (state) {
case DisplayOptionsState.success: case DisplayOptionsState.success:
Scaffold.of(context).showSnackBar(SnackBar( text = AppLocalizations.of(context).translate('success');
content: Text('Sucesso!'),
));
break; break;
case DisplayOptionsState.failure: case DisplayOptionsState.failure:
Scaffold.of(context).showSnackBar(SnackBar( text = AppLocalizations.of(context).translate('failure');
content: Text('Falha!'), backgroundColor = Colors.red;
backgroundColor: Colors.red,
));
break; break;
default: default:
break; break;
} }
_scaffoldKey.currentState.showSnackBar(SnackBar(
content: Text(text),
backgroundColor: backgroundColor,
));
}, },
child: SimpleDialog( child: SimpleDialog(
contentPadding: EdgeInsets.all(20.0), contentPadding: EdgeInsets.all(20.0),

View File

@ -34,8 +34,8 @@ dependencies:
url_launcher: ^5.1.2 url_launcher: ^5.1.2
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
bloc: ^0.14.0 bloc: ^0.15.0
flutter_bloc: ^0.20.0 flutter_bloc: ^0.21.0
equatable: ^0.4.0 equatable: ^0.4.0
http: ^0.12.0+2 http: ^0.12.0+2