This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter/widgets.dart'; | |
import 'package:timecoder/data/data_access/services/Values.dart'; | |
import 'package:timecoder/i18n/I18n.dart'; | |
import 'package:timecoder/ui/general/TCButton.dart'; | |
import 'package:timecoder/ui/general/TCErrorDialog.dart'; | |
import 'package:timecoder/ui/general/TCProgressIndicator.dart'; | |
import 'package:timecoder/ui/page/login_register/login/LoginPagePresenter.dart'; | |
import 'package:timecoder/ui/page/login_register/login/text_field/LoginTextField.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
void initState() { | |
controller.addListener(() => _viewModel.inputMailText.add(controller.text)); | |
super.initState(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
void initState() { | |
textFieldController.addListener(() { | |
var email = textFieldController.text; | |
var isValid = EmailValidator.isEmailValid(email); | |
var errorText; | |
if (!isValid) { | |
errorText = "Invalid email"; | |
} | |
setState(() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class SubscriptionViewModel { | |
Sink get inputMailText; | |
Stream<bool> get outputIsButtonEnabled; | |
Stream<String> get outputErrorText; | |
void dispose(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SubscriptionViewModelImpl implements SubscriptionViewModel { | |
var _mailTextController = StreamController<String>.broadcast(); | |
@override | |
Sink get inputMailText => _mailTextController; | |
@override | |
Stream<bool> get outputIsButtonEnabled => _mailTextController.stream | |
.map((email) => EmailValidator.isEmailValid(email)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StreamBuilder<String>( | |
stream: _viewModel.outputErrorText, | |
builder: (context, snapshot) { | |
return MyTextField( | |
controller: controller, | |
hintText: "Email", | |
errorText: snapshot.data); | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
Widget build(BuildContext context) { | |
return Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Expanded( | |
child: StreamBuilder<String>( | |
stream: _viewModel.outputErrorText, | |
builder: (context, snapshot) { | |
return MyTextField( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using "startWith" to ensure that the combined stream emitts even though | |
// on of two streams did not emmited any value yet | |
var combinedStream = Observable.combineLatest2( | |
title.startWith(""), | |
subtitle.startWith(""), | |
(title, subtitle) => Pair<String, String>(title, subtitle)); | |
new StreamBuilder<Pair<String, String>>( | |
stream: combinedStream, | |
builder: (_, snapshot) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailValidator { | |
static bool isEmailValid(String emailInput) { | |
if (_containsSemicolon(emailInput)) return false; | |
final String _emailRegex = | |
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$'; | |
RegExp emailRegExp = new RegExp(_emailRegex); | |
return emailRegExp.hasMatch(emailInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@immutable | |
class StreamWidget<T> extends StatelessWidget { | |
final Stream<T> stream; | |
final DataBuilder<T> builder; | |
final LoadingBuilder loadingBuilder; | |
final ErrorBuilder errorBuilder; | |
StreamWidget( | |
{@required this.stream, | |
@required this.builder, |
OlderNewer