This file contains hidden or 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 SharedPrefTokenRepository implements TokenRepository { | |
@override | |
Future<void> save(String token) async => | |
(await SharedPreferences.getInstance()) | |
.setString(_keyToken, token); | |
@override | |
Future<String> load() async => (await SharedPreferences.getInstance()) | |
.getString(_keyToken); |
This file contains hidden or 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 ApiThreadDataLayer implements ThreadDataLayer { | |
final RestClient _restClient; | |
@override | |
Future<Either<Exception, MessageThread>> createNewThread(…) async {…} | |
} |
This file contains hidden or 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 ThreadDataLayer { | |
Future<Either<Exception, MessageThread>> createNewThread( | |
String subject, | |
List<String> employeeIds, | |
); | |
} |
This file contains hidden or 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
Future<Either<Exception, MessageThread>> _createThread() async { | |
final selectedEmployees = | |
_selectedEmployees.value.map((employee) => employee.id).toList(); | |
return data.createNewThread(_title.value, selectedEmployees).map((thread) { | |
repository.saveThread(thread); | |
return thread; | |
}); | |
} |
This file contains hidden or 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 CreateThreadBloc extends BlocBase { | |
/// Title of the conversation | |
Stream<String> get title => _title.transform(emptyValidationTransformer); | |
final BehaviorSubject<String> _title = BehaviorSubject.seeded(''); | |
/// Creates new message thread or updates existing one. | |
Future<Either<Exception, MessageThread>> submit() async { | |
Either<Exception, MessageThread> result; | |
if (initialThread == null) { | |
result = await _createThread(); |
This file contains hidden or 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 CreateThreadScreen extends StatefulWidget {…} | |
class _CreateThreadScreenState extends State<CreateThreadScreen> { | |
@override | |
void afterInitState() { | |
super.afterInitState(); | |
bloc.title | |
.map((v) => _titleController.value.copyWith(text: v)) | |
.listen((v) => _titleController.value = v, onError: ignore) |
This file contains hidden or 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
📁 messages | |
📁 create_thread | |
create_thread_bloc.dart | |
create_thread_screen.dart | |
📁 models | |
message.dart | |
message_author.dart | |
message_thread.dart | |
📁 thread_details | |
thread_details_screen.dart |
This file contains hidden or 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
📁 profile | |
profile.dart | |
profile_bloc.dart | |
profile_screen.dart | |
📁 messages | |
📁 models | |
message.dart | |
thread.dart | |
messages_bloc.dart | |
messages_screen.dart |
This file contains hidden or 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
📁 models | |
message.dart | |
thread.dart | |
profile.dart | |
📁 blocs | |
messages_bloc.dart | |
profile_bloc.dart | |
📁 widgets | |
messages_screen.dart | |
profile_screen.dart |
This file contains hidden or 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
_messagesBloc = MessagesBloc(Provider.of(context), Provider.of(context)); |