diff --git a/lib/components/default_app_bar_search_field.dart b/lib/components/default_app_bar_search_field.dart index e31f48b3..c86390e5 100644 --- a/lib/components/default_app_bar_search_field.dart +++ b/lib/components/default_app_bar_search_field.dart @@ -7,6 +7,7 @@ class DefaultAppBarSearchField extends StatefulWidget { final bool autofocus; final String prefixText; final String hintText; + final EdgeInsets padding; const DefaultAppBarSearchField({ Key key, @@ -16,6 +17,7 @@ class DefaultAppBarSearchField extends StatefulWidget { this.autofocus = false, this.prefixText, this.hintText, + this.padding, }) : super(key: key); @override @@ -59,7 +61,7 @@ class _DefaultAppBarSearchFieldState extends State { Widget build(BuildContext context) { return Container( height: 40, - padding: EdgeInsets.only(right: 12), + padding: widget.padding ?? EdgeInsets.only(right: 12), child: Material( color: Theme.of(context).secondaryHeaderColor, borderRadius: BorderRadius.circular(32), diff --git a/lib/components/sentry_switch_list_tile.dart b/lib/components/sentry_switch_list_tile.dart index 943213c4..34925a27 100644 --- a/lib/components/sentry_switch_list_tile.dart +++ b/lib/components/sentry_switch_list_tile.dart @@ -3,6 +3,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; class SentrySwitchListTile extends StatefulWidget { + final String label; + + const SentrySwitchListTile({Key key, this.label}) : super(key: key); + @override _SentrySwitchListTileState createState() => _SentrySwitchListTileState(); } @@ -17,7 +21,7 @@ class _SentrySwitchListTileState extends State { builder: (context, snapshot) { _enabled = snapshot.data ?? false; return SwitchListTile( - title: Text(L10n.of(context).sendBugReports), + title: Text(widget.label ?? L10n.of(context).sendBugReports), value: _enabled, onChanged: (b) => SentryController.toggleSentryAction(context, b).then( diff --git a/lib/utils/platform_infos.dart b/lib/utils/platform_infos.dart index 02bb7248..d08dfc21 100644 --- a/lib/utils/platform_infos.dart +++ b/lib/utils/platform_infos.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:fluffychat/components/sentry_switch_list_tile.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:package_info/package_info.dart'; @@ -51,8 +52,9 @@ abstract class PlatformInfos { child: Text(AppConfig.emojiFontName), onPressed: () => launch(AppConfig.emojiFontUrl), ), + SentrySwitchListTile(label: L10n.of(context).sendBugReports), ], - applicationIcon: Image.asset('assets/logo.png', width: 100, height: 100), + applicationIcon: Image.asset('assets/logo.png', width: 64, height: 64), applicationName: AppConfig.applicationName, ); } diff --git a/lib/views/homeserver_picker.dart b/lib/views/homeserver_picker.dart index 3101ddf4..436d23de 100644 --- a/lib/views/homeserver_picker.dart +++ b/lib/views/homeserver_picker.dart @@ -1,11 +1,10 @@ import 'dart:math'; -import 'package:adaptive_dialog/adaptive_dialog.dart'; import 'package:adaptive_page_layout/adaptive_page_layout.dart'; import 'package:famedlysdk/famedlysdk.dart'; +import 'package:fluffychat/components/default_app_bar_search_field.dart'; import 'package:fluffychat/components/matrix.dart'; import 'package:fluffychat/app_config.dart'; -import 'package:fluffychat/components/sentry_switch_list_tile.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:flushbar/flushbar_helper.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; @@ -20,17 +19,19 @@ class HomeserverPicker extends StatefulWidget { class _HomeserverPickerState extends State { bool _isLoading = false; String _domain = AppConfig.defaultHomeserver; + final TextEditingController _controller = + TextEditingController(text: AppConfig.defaultHomeserver); void _checkHomeserverAction(BuildContext context) async { - var homeserver = _domain; - - if (!homeserver.startsWith('https://')) { - homeserver = 'https://$homeserver'; - } - - setState(() => _isLoading = true); - try { + if (_domain.isEmpty) throw L10n.of(context).changeTheHomeserver; + var homeserver = _domain; + + if (!homeserver.startsWith('https://')) { + homeserver = 'https://$homeserver'; + } + + setState(() => _isLoading = true); await Matrix.of(context).client.checkHomeserver(homeserver); final loginTypes = await Matrix.of(context).client.requestLoginTypes(); if (loginTypes.flows @@ -41,10 +42,12 @@ class _HomeserverPickerState extends State { .any((flow) => flow.type == AuthenticationTypes.sso)) { await AdaptivePageLayout.of(context).pushNamed('/sso'); } + } on String catch (e) { + // ignore: unawaited_futures + FlushbarHelper.createError(message: e).show(context); } catch (e) { // ignore: unawaited_futures FlushbarHelper.createError( - title: L10n.of(context).noConnectionToTheServer, message: (e as Object).toLocalizedString(context)) .show(context); } finally { @@ -54,29 +57,23 @@ class _HomeserverPickerState extends State { } } - void _changeHomeserverAction(BuildContext context) async { - final input = await showTextInputDialog( - context: context, - title: L10n.of(context).changeTheHomeserver, - textFields: [ - DialogTextField( - keyboardType: TextInputType.url, - prefixText: 'https://', - hintText: AppConfig.defaultHomeserver, - ), - ], - ); - if (input?.single?.isNotEmpty ?? false) { - setState(() => _domain = input.single); - } - } - @override Widget build(BuildContext context) { final padding = EdgeInsets.symmetric( horizontal: max((MediaQuery.of(context).size.width - 600) / 2, 0), ); return Scaffold( + appBar: AppBar( + title: DefaultAppBarSearchField( + prefixText: 'https://', + hintText: L10n.of(context).enterYourHomeserver, + searchController: _controller, + suffix: Icon(Icons.edit_outlined), + padding: padding, + onChanged: (s) => _domain = s, + ), + elevation: 0, + ), body: SafeArea( child: Padding( padding: padding, @@ -97,63 +94,6 @@ class _HomeserverPickerState extends State { ), ), ), - SizedBox(height: 16), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0), - child: Material( - borderRadius: BorderRadius.circular(16), - elevation: 2, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox(height: 8), - Text( - L10n.of(context).youWillBeConnectedTo(_domain), - style: TextStyle(fontSize: 16), - ), - FlatButton( - padding: EdgeInsets.all(8), - child: Text( - L10n.of(context).changeTheHomeserver, - style: TextStyle( - decoration: TextDecoration.underline, - fontSize: 16, - color: Colors.blue, - ), - ), - onPressed: () => _changeHomeserverAction(context), - ), - ], - ), - ), - ), - Wrap( - alignment: WrapAlignment.center, - children: [ - FlatButton( - padding: EdgeInsets.all(8), - child: Text( - L10n.of(context).privacy, - style: TextStyle( - decoration: TextDecoration.underline, - color: Colors.blueGrey, - ), - ), - onPressed: () => PlatformInfos.showDialog(context), - ), - FlatButton( - padding: EdgeInsets.all(8), - child: Text( - L10n.of(context).about, - style: TextStyle( - decoration: TextDecoration.underline, - color: Colors.blueGrey, - ), - ), - onPressed: () => PlatformInfos.showDialog(context), - ), - ], - ), ], ), ), @@ -186,7 +126,33 @@ class _HomeserverPickerState extends State { ), ), ), - SentrySwitchListTile(), + Wrap( + alignment: WrapAlignment.center, + children: [ + FlatButton( + padding: EdgeInsets.all(8), + child: Text( + L10n.of(context).privacy, + style: TextStyle( + decoration: TextDecoration.underline, + color: Colors.blueGrey, + ), + ), + onPressed: () => PlatformInfos.showDialog(context), + ), + FlatButton( + padding: EdgeInsets.all(8), + child: Text( + L10n.of(context).about, + style: TextStyle( + decoration: TextDecoration.underline, + color: Colors.blueGrey, + ), + ), + onPressed: () => PlatformInfos.showDialog(context), + ), + ], + ), ], ), ),