-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from maheini/dev
Dev
- Loading branch information
Showing
35 changed files
with
2,266 additions
and
302 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:racego/data/models/rankinglist.dart'; | ||
|
||
import '../../data/api/racego_api.dart'; | ||
import '../../data/exceptions/racego_exception.dart'; | ||
import '../../generated/l10n.dart'; | ||
|
||
part 'rankingcubit_state.dart'; | ||
|
||
class RankingCubit extends Cubit<RankingcubitState> { | ||
RankingCubit(RacegoApi api) | ||
: _api = api, | ||
super(const RankingLoading(currentClass: '', classList: [])) { | ||
loadClasses(); | ||
} | ||
final RacegoApi _api; | ||
|
||
List<String> _classes = []; | ||
String _currentClass = ''; | ||
RankingList _currentRanking = RankingList(null); | ||
|
||
Future<void> loadClasses() async { | ||
try { | ||
_classes = await _api.getCategories(); | ||
// if (!_classes.contains(_currentClass)) { | ||
// _currentClass = ''; | ||
// _classes.clear(); | ||
// } | ||
emit(RankingLoaded(_currentRanking, | ||
currentClass: _currentClass, classList: _classes)); | ||
} catch (e) { | ||
if (e is RacegoException) { | ||
emit(RankingError(e, currentClass: _currentClass, classList: _classes)); | ||
} else { | ||
UnknownException error = UnknownException( | ||
S.current.unknown_error, e.toString(), e.runtimeType.toString()); | ||
emit(RankingError(error, | ||
currentClass: _currentClass, classList: _classes)); | ||
} | ||
} | ||
} | ||
|
||
Future<void> loadRanking(String? raceClass) async { | ||
try { | ||
_currentRanking = await _api.getRankig(raceClass); | ||
emit(RankingLoaded(_currentRanking, | ||
currentClass: _currentClass, classList: _classes)); | ||
} catch (e) { | ||
if (e is RacegoException) { | ||
emit(RankingError(e, currentClass: _currentClass, classList: _classes)); | ||
} else { | ||
UnknownException error = UnknownException( | ||
S.current.unknown_error, e.toString(), e.runtimeType.toString()); | ||
emit(RankingError(error, | ||
currentClass: _currentClass, classList: _classes)); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
part of 'ranking_cubit.dart'; | ||
|
||
@immutable | ||
abstract class RankingcubitState { | ||
const RankingcubitState( | ||
{required this.currentClass, required this.classList}); | ||
final String currentClass; | ||
final List<String> classList; | ||
} | ||
|
||
class RankingLoading extends RankingcubitState { | ||
const RankingLoading( | ||
{required String currentClass, required List<String> classList}) | ||
: super(currentClass: currentClass, classList: classList); | ||
} | ||
|
||
class RankingLoaded extends RankingcubitState { | ||
const RankingLoaded(this.ranking, | ||
{required String currentClass, required List<String> classList}) | ||
: super(currentClass: currentClass, classList: classList); | ||
final RankingList ranking; | ||
} | ||
|
||
class RankingError extends RankingcubitState { | ||
const RankingError(this.exception, | ||
{required String currentClass, required List<String> classList}) | ||
: super(currentClass: currentClass, classList: classList); | ||
final RacegoException exception; | ||
} |
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
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
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
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
Oops, something went wrong.