Remove unused widgets

This commit is contained in:
Vishnu Mohandas 2020-09-05 14:59:56 +05:30
parent bc36bf8f5e
commit 46d9c45914
2 changed files with 0 additions and 566 deletions

View file

@ -1,205 +0,0 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/ui/sign_in_widget.dart';
import 'package:photos/utils/endpoint_finder.dart';
import 'package:photos/utils/toast_util.dart';
class SetupPage extends StatefulWidget {
SetupPage({key}) : super(key: key);
@override
_SetupPageState createState() => _SetupPageState();
}
class _SetupPageState extends State<SetupPage> {
bool _shouldSearchForEndpoint = true;
String _enteredEndpoint = "";
@override
Widget build(BuildContext context) {
if (Configuration.instance.getEndpoint() == null &&
_shouldSearchForEndpoint) {
EndpointFinder.instance.findEndpoint().then((endpoint) {
if (mounted && endpoint != null) {
showToast("Server discovery successful!");
setState(() {
Configuration.instance.setEndpoint(endpoint);
});
}
}).catchError((e) {
if (mounted) {
setState(() {
_shouldSearchForEndpoint = false;
});
}
});
}
return Scaffold(
appBar: AppBar(
title: Text("Setup"),
),
body: _getBody(),
);
}
Widget _getBody() {
if (Configuration.instance.getEndpoint() == null &&
_shouldSearchForEndpoint) {
return _getSearchScreen();
} else if (Configuration.instance.getEndpoint() == null &&
!_shouldSearchForEndpoint) {
return _getManualEndpointEntryScreen();
} else {
return SignInWidget(() {
setState(() {});
});
}
}
Widget _getManualEndpointEntryScreen() {
return Container(
margin: EdgeInsets.all(12),
child: Column(
children: <Widget>[
Text("Please enter the IP address of the ente server manually."),
TextField(
decoration: InputDecoration(
hintText: '192.168.1.1',
contentPadding: EdgeInsets.all(20),
),
autofocus: true,
autocorrect: false,
onChanged: (value) {
setState(() {
_enteredEndpoint = value;
});
},
),
CupertinoButton(
child: Text("Connect"),
onPressed: () async {
try {
bool success =
await EndpointFinder.instance.ping(_enteredEndpoint);
if (success) {
setState(() {
_shouldSearchForEndpoint = false;
Configuration.instance.setEndpoint(_enteredEndpoint);
});
} else {
_showPingErrorDialog();
}
} catch (e) {
_showPingErrorDialog();
}
},
),
],
),
);
}
Center _getSearchScreen() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
AnimatedSearchIconWidget(),
Text("Searching for server..."),
CupertinoButton(
child: Text("Enter manually instead"),
onPressed: () async {
EndpointFinder.instance.cancelSearch();
setState(() {
_shouldSearchForEndpoint = false;
});
},
),
],
),
);
}
void _showPingErrorDialog() {
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text('Connection failed'),
content: Padding(
padding: const EdgeInsets.fromLTRB(0, 8, 0, 0),
child: Text(
'Please make sure that the server is running and reachable.'),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
}
class AnimatedSearchIconWidget extends StatefulWidget {
AnimatedSearchIconWidget({
Key key,
}) : super(key: key);
@override
_AnimatedSearchIconWidgetState createState() =>
_AnimatedSearchIconWidgetState();
}
class _AnimatedSearchIconWidgetState extends State<AnimatedSearchIconWidget>
with SingleTickerProviderStateMixin {
Animation<double> _animation;
AnimationController _controller;
@override
void initState() {
super.initState();
_controller =
AnimationController(duration: const Duration(seconds: 1), vsync: this);
_animation = Tween<double>(begin: 100, end: 200).animate(_controller)
..addListener(() {
if (mounted) {
setState(() {});
}
})
..addStatusListener((status) {
if (status == AnimationStatus.completed) {
_controller.reverse();
} else if (status == AnimationStatus.dismissed) {
_controller.forward();
}
});
_controller.forward();
}
@override
Widget build(BuildContext context) {
return Container(
child: Icon(
Icons.search,
size: _animation.value,
),
width: 200,
height: 200,
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}

View file

@ -1,361 +0,0 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:photos/core/configuration.dart';
import 'package:photos/core/event_bus.dart';
import 'package:photos/events/user_authenticated_event.dart';
import 'package:photos/user_authenticator.dart';
class SignInWidget extends StatefulWidget {
final Function() onReconfigurationRequested;
const SignInWidget(
this.onReconfigurationRequested, {
Key key,
}) : super(key: key);
@override
_SignInWidgetState createState() => _SignInWidgetState();
}
enum Mode { sign_up, sign_in, unknown }
class _SignInWidgetState extends State<SignInWidget> {
Mode mode = Mode.unknown;
final _usernameController = TextEditingController();
final _passwordController = TextEditingController();
final _repeatPasswordController = TextEditingController();
@override
Widget build(BuildContext context) {
if (mode == Mode.sign_up) {
return _getSignUpWidget(context);
} else {
return _getSignInWidget(context);
}
}
Widget _getSignUpWidget(BuildContext context) {
return Container(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
child: Text("Create an account to get started"),
),
TextFormField(
decoration: InputDecoration(
hintText: 'username',
contentPadding: EdgeInsets.all(20),
),
controller: _usernameController,
autofocus: true,
autocorrect: false,
),
TextFormField(
decoration: InputDecoration(
hintText: 'password',
contentPadding: EdgeInsets.all(20),
),
autocorrect: false,
obscureText: true,
controller: _passwordController,
),
TextFormField(
decoration: InputDecoration(
hintText: 'repeat password',
contentPadding: EdgeInsets.all(20),
),
autocorrect: false,
obscureText: true,
controller: _repeatPasswordController,
),
CupertinoButton(
child: Text("Sign Up"),
onPressed: () async {
if (_passwordController.text != _repeatPasswordController.text) {
_showPasswordMismatchDialog();
} else {
try {
final userCreated = await UserAuthenticator.instance.create(
_usernameController.text, _passwordController.text);
if (userCreated) {
Navigator.of(context).pop();
_showSelectEncryptionLevelDialog();
} else {
_showGenericErrorDialog();
}
} catch (e) {
_showGenericErrorDialog(error: e);
}
}
},
),
CupertinoButton(
child: Text("Have an account?"),
onPressed: () {
setState(() {
mode = Mode.sign_in;
});
},
),
],
),
));
}
Widget _getSignInWidget(BuildContext context) {
return Container(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextFormField(
// initialValue: Configuration.instance.getUsername(),
decoration: InputDecoration(
hintText: 'username',
contentPadding: EdgeInsets.all(20),
),
autofocus: true,
autocorrect: false,
controller: _usernameController,
),
TextFormField(
// initialValue: Configuration.instance.getPassword(),
decoration: InputDecoration(
hintText: 'password',
contentPadding: EdgeInsets.all(20),
),
autocorrect: false,
obscureText: true,
controller: _passwordController,
),
CupertinoButton(
child: Text("Sign In"),
onPressed: () async {
final loggedIn = await UserAuthenticator.instance
.login(_usernameController.text, _passwordController.text);
if (loggedIn) {
Navigator.of(context).pop();
if (Configuration.instance.getEncryptedKey() != null) {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return PassphraseDialog(false);
},
);
}
} else {
_showAuthenticationFailedErrorDialog();
}
},
),
CupertinoButton(
child: Text("Don't have an account?"),
onPressed: () {
setState(() {
mode = Mode.sign_up;
});
},
),
],
),
));
}
void _showPasswordMismatchDialog() {
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text("Passwords don't match"),
content: Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
child: Text("Please make sure that the passwords you enter match."),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
void _showGenericErrorDialog({Exception error}) {
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text("Ooops."),
content: Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
child: error == null
? Text("Something went wrong.")
: Text(error.toString()),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
void _showAuthenticationFailedErrorDialog() {
showDialog<void>(
context: context,
barrierDismissible: false, // user must tap button!
builder: (BuildContext context) {
return CupertinoAlertDialog(
title: Text('Login failed'),
content: Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
child: Text(
'Please make sure that the credentials entered are correct.'),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text('Reconfigure'),
onPressed: () {
Navigator.of(context).pop();
Configuration.instance.setEndpoint(null);
widget.onReconfigurationRequested();
},
),
CupertinoDialogAction(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
void _showSelectEncryptionLevelDialog() {
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return SelectEncryptionLevelWidget();
},
);
}
}
class SelectEncryptionLevelWidget extends StatelessWidget {
const SelectEncryptionLevelWidget({
Key key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return CupertinoAlertDialog(
title: Text('Choose encryption level'),
content: Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
child: Column(
children: [
Text('Would you like to enable end-to-end encryption?'),
Padding(padding: EdgeInsets.all(8)),
Text(
'This will mean you will not be able to use features like search and sharing.'),
],
),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text('Use E2E encryption'),
onPressed: () {
Navigator.of(context).pop();
Configuration.instance.setOptInForE2E(true);
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return PassphraseDialog(true);
},
);
},
),
CupertinoDialogAction(
child: Text("Use encryption at rest"),
onPressed: () {
Navigator.of(context).pop();
Configuration.instance.setOptInForE2E(false);
Bus.instance.fire(UserAuthenticatedEvent());
},
),
],
);
}
}
class PassphraseDialog extends StatefulWidget {
final bool isFreshRegistration;
const PassphraseDialog(
this.isFreshRegistration, {
Key key,
}) : super(key: key);
@override
_PassphraseDialogState createState() => _PassphraseDialogState();
}
class _PassphraseDialogState extends State<PassphraseDialog> {
String _passphrase = "";
@override
Widget build(BuildContext context) {
return CupertinoAlertDialog(
title: Text('Enter passphrase'),
content: Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
child: Column(
children: [
CupertinoTextField(
autofocus: true,
style: Theme.of(context).textTheme.subtitle1,
keyboardType: TextInputType.visiblePassword,
onChanged: (value) {
_passphrase = value;
},
),
],
),
),
actions: <Widget>[
CupertinoDialogAction(
child: Text('Save'),
onPressed: () async {
Navigator.of(context).pop();
if (widget.isFreshRegistration) {
await Configuration.instance.generateAndSaveKey(_passphrase);
await UserAuthenticator.instance.setEncryptedKeyOnServer();
} else {
await Configuration.instance.decryptAndSaveKey(_passphrase, null);
}
Bus.instance.fire(UserAuthenticatedEvent());
},
)
],
);
}
}