Preclean
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class AuthBloc extends Bloc {
|
||||
AuthBloc();
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export 'auth-bloc.dart';
|
||||
export 'pref-bloc.dart';
|
||||
42
web_native/lib/blocs/login/bloc.dart
Normal file
42
web_native/lib/blocs/login/bloc.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import 'package:imagini/blocs/login/events.dart';
|
||||
import 'package:imagini/blocs/login/states.dart';
|
||||
import 'package:imagini/services/api/api.dart';
|
||||
import 'package:imagini/services/api/exceptions.dart';
|
||||
|
||||
class LoginBloc extends Bloc<LoginEvents, LoginState> {
|
||||
final ImaginiAPI imaginiAPI;
|
||||
Map<String, String> loginResult;
|
||||
String exampleResult;
|
||||
|
||||
LoginBloc({ this.imaginiAPI }) : super(LoginInitState());
|
||||
|
||||
@override
|
||||
Stream<LoginState> mapEventToState(LoginEvents event) async* {
|
||||
switch (event) {
|
||||
case LoginEvents.loginResult:
|
||||
yield LoginLoading();
|
||||
try {
|
||||
// exampleResult = await imaginiAPI.exampleApi();
|
||||
loginResult = await imaginiAPI.loginAPI("admin", "admin");
|
||||
yield LoginSuccess();
|
||||
} on SocketException {
|
||||
yield LoginFailed(
|
||||
error: ConnectionRefusedException('No Internet'),
|
||||
);
|
||||
} on FormatException {
|
||||
yield LoginFailed(
|
||||
error: InvalidFormatException('Invalid Response Format'),
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
yield LoginFailed(
|
||||
error: UnknownException('Unknown Error'),
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
web_native/lib/blocs/login/events.dart
Normal file
3
web_native/lib/blocs/login/events.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
enum LoginEvents {
|
||||
loginResult,
|
||||
}
|
||||
28
web_native/lib/blocs/login/states.dart
Normal file
28
web_native/lib/blocs/login/states.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
// import 'package:equatable/equatable.dart';
|
||||
//
|
||||
// abstract class LoginState extends Equatable {
|
||||
// @override
|
||||
// List<Object> get props => [];
|
||||
// }
|
||||
|
||||
abstract class LoginState {}
|
||||
|
||||
class LoginInitState extends LoginState {}
|
||||
|
||||
class LoginLoading extends LoginState {}
|
||||
|
||||
class LoginSuccess extends LoginState {}
|
||||
|
||||
class LoginNeeded extends LoginState {}
|
||||
|
||||
class LoginFailed extends LoginState {
|
||||
final error;
|
||||
LoginFailed({this.error});
|
||||
}
|
||||
|
||||
class LoginLoaded extends LoginState {}
|
||||
|
||||
class LoginListError extends LoginState {
|
||||
final error;
|
||||
LoginListError({this.error});
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
import 'package:imagini/bloc/bloc.dart';
|
||||
|
||||
class PrefBloc extends Bloc {
|
||||
PrefBloc();
|
||||
}
|
||||
23
web_native/lib/blocs/theme/bloc.dart
Normal file
23
web_native/lib/blocs/theme/bloc.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:imagini/blocs/theme/events.dart';
|
||||
import 'package:imagini/blocs/theme/state.dart';
|
||||
import 'package:imagini/settings/app_themes.dart';
|
||||
|
||||
class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
|
||||
//
|
||||
ThemeBloc()
|
||||
: super(
|
||||
ThemeState(
|
||||
themeData: AppThemes.appThemeData[AppTheme.lightTheme],
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Stream<ThemeState> mapEventToState(ThemeEvent event) async* {
|
||||
if (event is ThemeEvent) {
|
||||
yield ThemeState(
|
||||
themeData: AppThemes.appThemeData[event.appTheme],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
6
web_native/lib/blocs/theme/events.dart
Normal file
6
web_native/lib/blocs/theme/events.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:imagini/settings/app_themes.dart';
|
||||
|
||||
class ThemeEvent {
|
||||
final AppTheme appTheme;
|
||||
ThemeEvent({this.appTheme});
|
||||
}
|
||||
6
web_native/lib/blocs/theme/state.dart
Normal file
6
web_native/lib/blocs/theme/state.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ThemeState {
|
||||
final ThemeData themeData;
|
||||
ThemeState({this.themeData});
|
||||
}
|
||||
Reference in New Issue
Block a user