Skip to content

Commit

Permalink
Noissue - apply dartfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
4ntoine committed Dec 20, 2019
1 parent b719bb3 commit 34eaf38
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 241 deletions.
13 changes: 5 additions & 8 deletions app-flutter/lib/add_note/add_note_load_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ class AddNoteLoadErrorState extends AddNoteLoadState {
AddNoteLoadErrorState(this._error);

@override
Widget getWidget() => Center(child: Text(
_error.toString(),
style: TextStyle(
fontSize: 18.0,
color: Colors.red,
fontWeight: FontWeight.bold)
));
}
Widget getWidget() => Center(
child: Text(_error.toString(),
style: TextStyle(
fontSize: 18.0, color: Colors.red, fontWeight: FontWeight.bold)));
}
91 changes: 48 additions & 43 deletions app-flutter/lib/add_note/add_note_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class _AddNoteScreenState extends State<AddNoteScreen> {
setState(() {
_state = AddNoteLoadingState();
final request = AddNoteRequest(
_titleController.text.trim(),
_bodyController.text.trim());
_titleController.text.trim(), _bodyController.text.trim());
widget._useCase.addNote(request).then((response) {
setState(() {
final id = response.id;
Expand All @@ -48,66 +47,72 @@ class _AddNoteScreenState extends State<AddNoteScreen> {
final double interMargin = Platform.isAndroid ? 0 : 10;
return _state != null
? _state.getWidget()
: Column(children: <Widget> [
: Column(children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 10, right: 10),
child: Platform.isAndroid // title
? TextField(
decoration: new InputDecoration(hintText: 'Title'),
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _titleController)
: CupertinoTextField(
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _titleController
)),
padding: EdgeInsets.only(left: 10, right: 10),
child: Platform.isAndroid // title
? TextField(
decoration: new InputDecoration(hintText: 'Title'),
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _titleController)
: CupertinoTextField(
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _titleController)),
Padding(
padding: EdgeInsets.only(left: 10, top: interMargin, right: 10),
child: Platform.isAndroid // body
? TextField(
decoration: new InputDecoration(hintText: 'Body'),
keyboardType: TextInputType.number,
maxLines: 1,
controller: _bodyController)
: CupertinoTextField(
keyboardType: TextInputType.number,
maxLines: 1,
controller: _bodyController)),
padding: EdgeInsets.only(left: 10, top: interMargin, right: 10),
child: Platform.isAndroid // body
? TextField(
decoration: new InputDecoration(hintText: 'Body'),
keyboardType: TextInputType.number,
maxLines: 1,
controller: _bodyController)
: CupertinoTextField(
keyboardType: TextInputType.number,
maxLines: 1,
controller: _bodyController)),
Platform.isAndroid
? RaisedButton(child: Text('OK'), onPressed: () { _onInputFinished(); })
: CupertinoButton(child: Text('OK'), onPressed: () { _onInputFinished(); })
? RaisedButton(
child: Text('OK'),
onPressed: () {
_onInputFinished();
})
: CupertinoButton(
child: Text('OK'),
onPressed: () {
_onInputFinished();
})
]);
}

@override
Widget build(BuildContext context) {
final double topMargin = Platform.isAndroid ? 0 : 105; // TODO: (why margin on iOS?)
final double topMargin =
Platform.isAndroid ? 0 : 105; // TODO: (why margin on iOS?)
return Platform.isAndroid
? Scaffold(
appBar: AppBar(title: Text('Add note')),
body: _getWidget())
: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(middle: Text('Add note')),
child: Padding(
padding: EdgeInsets.only(top: topMargin),
child: _getWidget()));
? Scaffold(appBar: AppBar(title: Text('Add note')), body: _getWidget())
: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(middle: Text('Add note')),
child: Padding(
padding: EdgeInsets.only(top: topMargin), child: _getWidget()));
}
}

class AddNoteScreen extends StatefulWidget {
static const route = '/addNote';
static navigateTo(BuildContext context, [bool cleanStack = true]) =>
Platform.isAndroid
static navigateTo(BuildContext context, [bool cleanStack = true]) => Platform
.isAndroid
? Navigator.pushNamedAndRemoveUntil(context, route, (_) => !cleanStack)
: Navigator.push(context, CupertinoPageRoute(builder: MyApp.addNoteScreenBuilder));
: Navigator.push(
context, CupertinoPageRoute(builder: MyApp.addNoteScreenBuilder));

final AddNoteUseCase _useCase;
final AddNoteCallback _callback;
AddNoteScreen(this._useCase, this._callback, {Key key}) : super(key: key);

@override
_AddNoteScreenState createState() => _AddNoteScreenState();
}
}
27 changes: 12 additions & 15 deletions app-flutter/lib/add_note/add_note_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class AddNoteRequestJson {
final String id;
AddNoteRequestJson(this.id);

Map<String, dynamic> toJson()
=> _$AddNoteRequestJsonToJson(this);
Map<String, dynamic> toJson() => _$AddNoteRequestJsonToJson(this);
}

@JsonSerializable(createToJson: false)
Expand All @@ -41,8 +40,8 @@ class AddNoteResponseJson {
final String id;
AddNoteResponseJson(this.id);

factory AddNoteResponseJson.fromJson(Map<String, dynamic> json)
=> _$AddNoteResponseJsonFromJson(json);
factory AddNoteResponseJson.fromJson(Map<String, dynamic> json) =>
_$AddNoteResponseJsonFromJson(json);
}

// impl that interacts with server over http (json)
Expand All @@ -54,22 +53,20 @@ class ServerAddNoteInteractor extends AddNoteUseCase {
@override
Future<AddNoteResponse> addNote(AddNoteRequest request) async {
final client = _client ?? http.Client();
final queryParams = {
'title' : request.title,
'body' : request.body
};
final queryParams = {'title': request.title, 'body': request.body};
final uri = Uri(
scheme: _uri.scheme,
host: _uri.host,
port: _uri.port,
path: _uri.path,
queryParameters: queryParams);
scheme: _uri.scheme,
host: _uri.host,
port: _uri.port,
path: _uri.path,
queryParameters: queryParams);
final response = await client.get(uri);
if (response.statusCode == 200) {
final addResponse = AddNoteResponseJson.fromJson(json.decode(response.body));
final addResponse =
AddNoteResponseJson.fromJson(json.decode(response.body));
return AddNoteResponse(addResponse.id);
} else {
throw Exception('Unexpected HTTP status code: ${response.statusCode}');
}
}
}
}
78 changes: 40 additions & 38 deletions app-flutter/lib/connection/connection_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,63 +9,65 @@ class Connection {
final int port;
Connection(this.host, this.port);
}

typedef ConnectionScreenCallback = void Function(Connection connection);

class _ConnectionState extends State<ConnectionScreen> {
final _hostController = TextEditingController(text: defaultConnection.host);
final _portController = TextEditingController(text: defaultConnection.port.toString());
final _portController =
TextEditingController(text: defaultConnection.port.toString());

_onInputFinished() {
// TODO: add validation

final connection = Connection(
_hostController.text.trim(),
int.tryParse(_portController.text.trim()));
_hostController.text.trim(), int.tryParse(_portController.text.trim()));
widget._callback(connection);
}

@override
Widget build(BuildContext context) {
final double topMargin = Platform.isAndroid ? 0 : 105; // TODO: (why margin on iOS?)
final double topMargin =
Platform.isAndroid ? 0 : 105; // TODO: (why margin on iOS?)
final double interMargin = Platform.isAndroid ? 0 : 10;
final body = Column(children: <Widget> [
final body = Column(children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 10, right: 10, top: topMargin),
child: Platform.isAndroid // url
? TextField(
decoration: new InputDecoration(hintText: 'Host'),
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _hostController)
: CupertinoTextField(
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _hostController)),
padding: EdgeInsets.only(left: 10, right: 10, top: topMargin),
child: Platform.isAndroid // url
? TextField(
decoration: new InputDecoration(hintText: 'Host'),
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _hostController)
: CupertinoTextField(
maxLines: 1,
autofocus: true,
textInputAction: TextInputAction.next,
controller: _hostController)),
Padding(
padding: EdgeInsets.only(left: 10, top: interMargin, right: 10),
child: Platform.isAndroid // port
? TextField(
decoration: new InputDecoration(hintText: 'Port'),
keyboardType: TextInputType.number,
maxLines: 1,
controller: _portController)
: CupertinoTextField(
keyboardType: TextInputType.number,
maxLines: 1,
controller: _portController)),
padding: EdgeInsets.only(left: 10, top: interMargin, right: 10),
child: Platform.isAndroid // port
? TextField(
decoration: new InputDecoration(hintText: 'Port'),
keyboardType: TextInputType.number,
maxLines: 1,
controller: _portController)
: CupertinoTextField(
keyboardType: TextInputType.number,
maxLines: 1,
controller: _portController)),
Platform.isAndroid
? RaisedButton(child: Text('OK'), onPressed: () => _onInputFinished())
: CupertinoButton(child: Text('OK'), onPressed: () => _onInputFinished())
? RaisedButton(child: Text('OK'), onPressed: () => _onInputFinished())
: CupertinoButton(
child: Text('OK'), onPressed: () => _onInputFinished())
]);
return Platform.isAndroid
? Scaffold(
appBar: AppBar(title: Text('Server connection')),
body: body)
: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(middle: Text('Server connection')),
child: body);
? Scaffold(appBar: AppBar(title: Text('Server connection')), body: body)
: CupertinoPageScaffold(
navigationBar:
CupertinoNavigationBar(middle: Text('Server connection')),
child: body);
}
}

Expand All @@ -77,4 +79,4 @@ class ConnectionScreen extends StatefulWidget {

@override
_ConnectionState createState() => _ConnectionState();
}
}
4 changes: 2 additions & 2 deletions app-flutter/lib/connection/connection_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class ConnectionWidget extends InheritedWidget {
}

static ConnectionWidget of(BuildContext context) =>
context.dependOnInheritedWidgetOfExactType<ConnectionWidget>();
}
context.dependOnInheritedWidgetOfExactType<ConnectionWidget>();
}
Loading

0 comments on commit 34eaf38

Please sign in to comment.