update
This commit is contained in:
parent
a76d3a0f35
commit
e3dc94a768
33 changed files with 368 additions and 184 deletions
14
lib/blocs/user/functions/bloc_getuser.dart
Normal file
14
lib/blocs/user/functions/bloc_getuser.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_event.dart';
|
||||
|
||||
Future<String> blocGetUser(BuildContext context) async {
|
||||
try {
|
||||
final userBloc = context.read<UserBloc>();
|
||||
userBloc.add(UserGetValue());
|
||||
return userBloc.state.value;
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
14
lib/blocs/user/functions/bloc_setuser.dart
Normal file
14
lib/blocs/user/functions/bloc_setuser.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_event.dart';
|
||||
|
||||
Future<bool> blocSetUser(BuildContext context, String value) async {
|
||||
try {
|
||||
final userBloc = context.read<UserBloc>();
|
||||
userBloc.add(UserSetValue(value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
14
lib/blocs/user/user_bloc.dart
Normal file
14
lib/blocs/user/user_bloc.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_event.dart';
|
||||
import 'package:pharmacy_mobile/blocs/user/user_state.dart';
|
||||
|
||||
class UserBloc extends Bloc<UserEvent, UserState> {
|
||||
UserBloc() : super(UserState('')) {
|
||||
on<UserSetValue>((event, emit) {
|
||||
emit(UserState(event.value));
|
||||
});
|
||||
on<UserGetValue>((event, emit) {
|
||||
emit(state);
|
||||
});
|
||||
}
|
||||
}
|
||||
8
lib/blocs/user/user_event.dart
Normal file
8
lib/blocs/user/user_event.dart
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
abstract class UserEvent {}
|
||||
|
||||
class UserSetValue extends UserEvent {
|
||||
final String value;
|
||||
UserSetValue(this.value);
|
||||
}
|
||||
|
||||
class UserGetValue extends UserEvent {}
|
||||
5
lib/blocs/user/user_state.dart
Normal file
5
lib/blocs/user/user_state.dart
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class UserState {
|
||||
final String value;
|
||||
|
||||
UserState(this.value);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue