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_port_title": "Type the port",
"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_localizations/flutter_localizations.dart';
import 'src/bloc/display_options_dialog_bloc.dart';
import 'src/bloc/settings_bloc.dart';
import 'src/openlp_mobile_remote_app.dart';
import 'src/configurations/app_theme.dart';
import 'src/configurations/app_localizations.dart';
import 'src/screens/settings.dart';
void main() => runApp(
MaterialApp(
void main() => runApp(MultiBlocProvider(
providers: [
BlocProvider<DisplayOptionsDialogBloc>(
builder: (context) => DisplayOptionsDialogBloc(),
),
BlocProvider<SettingsBloc>(
builder: (context) => SettingsBloc(),
),
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: appTheme,
supportedLocales: [
@ -62,10 +71,7 @@ void main() => runApp(
},
routes: <String, WidgetBuilder>{
'/': (context) => OpenLPMobileRemoteApp(),
'/settings': (context) => BlocProvider(
builder: (context) => SettingsBloc(),
child: Settings(),
),
'/settings': (context) => Settings(),
},
),
);
));

View File

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

View File

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

View File

@ -35,6 +35,10 @@ class _Action {
}
class AppBottomNavigationBar extends StatelessWidget {
final GlobalKey<ScaffoldState> _scaffoldKey;
AppBottomNavigationBar(this._scaffoldKey);
@override
Widget build(BuildContext context) {
final List<_Action> _actions = [
@ -54,7 +58,7 @@ class AppBottomNavigationBar extends StatelessWidget {
() {
showDialog(
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
Widget build(BuildContext context) {
final bloc = DisplayOptionsDialogBloc();
final bloc = BlocProvider.of<DisplayOptionsDialogBloc>(context);
return BlocListener<DisplayOptionsDialogBloc, DisplayOptionsState>(
bloc: bloc,
condition: (previous, current) => current != DisplayOptionsState.none,
condition: (previous, current) => current != DisplayOptionsState.waiting,
listener: (context, state) {
print(state);
String text;
Color backgroundColor;
switch (state) {
case DisplayOptionsState.success:
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Sucesso!'),
));
text = AppLocalizations.of(context).translate('success');
break;
case DisplayOptionsState.failure:
Scaffold.of(context).showSnackBar(SnackBar(
content: Text('Falha!'),
backgroundColor: Colors.red,
));
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),

View File

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