This Trading App provides a platform to view real-time trading data, market trends, and price changes using Flutter and the BLoC pattern. The app displays aggregated market trends in real-time with dynamic charts.
Continuous Integration and Deployment (CI/CD) are set up to below link ensure quality and streamline deployment. https://farhatbaig.github.io/tradingApp/
- application: Contains
Blocclasses for managing business logic and state. - domain: Defines core entities and abstractions for data handling.
- infrastructure: Manages data sources and repositories for API calls.
- presentation: Holds UI components such as screens and widgets.
- Manages state using the BLoC (Business Logic Component) pattern, providing a clear separation of concerns and predictable state management.
freezed: Generates immutable data classes to ensure data integrity.json_serializable: Automatically handles JSON serialization and deserialization.
- Brings functional programming constructs like
EitherandOptionfor better error handling and functional operations.
- Renders beautiful, interactive charts to display trading data and market trends dynamically.
-
Install Dependencies:
flutter pub get
-
Generate Freezed Classes:
flutter pub run build_runner build
-
Run the App:
flutter run
-
Run Tests:
flutter test
To run the app on an iPhone emulator or an Android device, follow these steps:
- Ensure Xcode is installed and set up on your Mac.
- Open an iOS simulator:
open -a Simulator
flutter run -d ios
-
Enable Developer Options and USB Debugging on your Android device.
-
Connect the device to your computer via USB.
-
Verify the device connection:
flutter devices
flutter run -d <device-id>
The Bloc pattern is used for managing business logic and state changes in response to UI events. Each bloc:
- Takes in events dispatched from the UI.
- Processes business logic.
- Emits states back to the UI.
Repositories abstract data access logic. This app uses a SymbolRepository to handle API interactions, separating data sources (such as APIs) from the app's business logic.
Freezed classes define immutable data structures. This enables predictable data flow and ensures data integrity across different parts of the app.
Below is an example of how BLoC and repository patterns are used:
// In the BLoC
class TradingBloc extends Bloc<TradingEvent, TradingState> {
final SymbolRepository symbolRepository;
TradingBloc({required this.symbolRepository}) : super(TradingState.initial()) {
on<FetchSymbols>(_onFetchSymbols);
}
Future<void> _onFetchSymbols(FetchSymbols event, Emitter<TradingState> emit) async {
final symbols = await symbolRepository.getSymbolData();
emit(TradingState.loaded(symbols: symbols, prices: {}));
}
}