From e2620a579998486d79420aaef4824993d040aea1 Mon Sep 17 00:00:00 2001 From: Ivo Fernandes Date: Thu, 14 Dec 2023 01:27:49 +0000 Subject: [PATCH] Improved card UI --- .../ui/big_picture_resume_list.dart | 6 ++- .../ui/resume/strategy_resume_header_ui.dart | 7 ++- .../ui/resume/strategy_resume_ui.dart | 46 ++++++++++++++++--- pubspec.lock | 4 +- pubspec.yaml | 4 +- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/lib/big_picture/ui/big_picture_resume_list.dart b/lib/big_picture/ui/big_picture_resume_list.dart index d33753e..9dc3817 100644 --- a/lib/big_picture/ui/big_picture_resume_list.dart +++ b/lib/big_picture/ui/big_picture_resume_list.dart @@ -41,7 +41,11 @@ class BigPictureResumeList extends StatelessWidget { for (int i = index * columns; i < (index + 1) * columns && i < tickers.length; i++) { final StockTicker ticker = tickers[i]; final BuyAndHoldStrategyResult? strategy = data[ticker]; - resumes.add(StrategyResume(ticker, strategy!, width / columns)); + resumes.add(StrategyResume( + ticker, + strategy!, + width / columns, + )); } return Wrap( children: resumes, diff --git a/lib/big_picture/ui/resume/strategy_resume_header_ui.dart b/lib/big_picture/ui/resume/strategy_resume_header_ui.dart index 2900fdd..1fb2e9b 100644 --- a/lib/big_picture/ui/resume/strategy_resume_header_ui.dart +++ b/lib/big_picture/ui/resume/strategy_resume_header_ui.dart @@ -55,7 +55,10 @@ class StrategyResumeHeader extends StatelessWidget { )) ], ), - Divider(height: 5, color: theme.textTheme.bodyLarge!.color), + Divider( + height: 5, + color: theme.textTheme.bodyLarge!.color, + ), bigPictureState.isCompactView() ? Container() : const SizedBox(height: 10), bigPictureState.isCompactView() ? Container() @@ -71,7 +74,7 @@ class StrategyResumeHeader extends StatelessWidget { ), bigPictureState.isCompactView() ? Container() : const SizedBox(height: 10) ]), - bigPictureState.isCompactView() || ticker.symbol.contains(',') + bigPictureState.isCompactView() ? Container() : InkWell( child: Container( diff --git a/lib/big_picture/ui/resume/strategy_resume_ui.dart b/lib/big_picture/ui/resume/strategy_resume_ui.dart index e6d0027..5ec749a 100644 --- a/lib/big_picture/ui/resume/strategy_resume_ui.dart +++ b/lib/big_picture/ui/resume/strategy_resume_ui.dart @@ -9,15 +9,20 @@ import 'package:turing_deal/big_picture/state/big_picture_state_provider.dart'; import 'package:turing_deal/big_picture/ui/resume/strategy_resume_details_ui.dart'; import 'package:turing_deal/big_picture/ui/resume/strategy_resume_header_ui.dart'; +/// StrategyResume is a StatelessWidget that displays the resume of a stock trading strategy. +/// It shows a card with details of the strategy's performance for a given stock ticker. class StrategyResume extends StatelessWidget { + // Constants for layout configuration static const double resumeWidth = 320; static const double resumeLeftColumn = 140 - 15; static const double resumeRightColumn = resumeWidth - resumeLeftColumn - 30; + // Variables to hold ticker and strategy information final StockTicker ticker; final BuyAndHoldStrategyResult strategy; final double width; + /// Constructor for StrategyResume const StrategyResume( this.ticker, this.strategy, @@ -27,22 +32,24 @@ class StrategyResume extends StatelessWidget { @override Widget build(BuildContext context) { + // Accessing the state provider final BigPictureStateProvider bigPictureState = Provider.of(context, listen: false); + // Calculating screen width and card width final double screenWidth = window.physicalSize.width / window.devicePixelRatio; final int columns = (screenWidth / resumeWidth).floor(); double cardWidth = resumeWidth + (screenWidth % resumeWidth / columns); + // Adjusting card width for compact view if (bigPictureState.isCompactView()) { cardWidth /= 3; cardWidth -= 5; print('card width: $cardWidth'); } + // Main widget structure return Dismissible( key: GlobalKey(), - // Provide a function that tells the app - // what to do after an item has been swiped away. onDismissed: (direction) => bigPictureState.removeTicker(ticker), background: const ColoredBox( color: Colors.red, @@ -63,8 +70,31 @@ class StrategyResume extends StatelessWidget { } }, child: PinchZoomReleaseUnzoomWidget( - child: Card( + child: Container( + margin: const EdgeInsets.only(top: 5), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + boxShadow: [ + BoxShadow( + color: Theme.of(context).colorScheme.primary, + blurRadius: 2, + offset: const Offset(2, 2), // Adjust the offset to control the shadow direction + ), + ], + ), child: Container( + decoration: BoxDecoration( + color: Theme.of(context).cardColor, + borderRadius: BorderRadius.circular(20), + boxShadow: [ + BoxShadow( + color: Theme.of(context).cardColor, + blurRadius: 2, + offset: const Offset(2, 2), // Adjust the offset to control the shadow direction + ), + ], + ), + margin: const EdgeInsets.all(5), padding: const EdgeInsets.all(10), child: strategy.progress > 0 ? Column( @@ -74,10 +104,12 @@ class StrategyResume extends StatelessWidget { strategy.progress < 100 ? const CircularProgressIndicator() : Container() ], ) - : Column( - children: const [ - CircularProgressIndicator(), - ], + : const Center( + child: SizedBox( + width: 25, + height: 25, + child: CircularProgressIndicator(), + ), ), ), ), diff --git a/pubspec.lock b/pubspec.lock index 59d6bb6..898bd6b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -686,10 +686,10 @@ packages: dependency: "direct main" description: name: ticker_search - sha256: "3a39f78f75594b0083d4d998c7b5fcacf4ccc7e1b6e890f006fe436ca7995ff4" + sha256: "841927b87dd1085bea22a2a5bd963b426b9ba5910461d48d4c836abe587f2fce" url: "https://pub.dev" source: hosted - version: "0.0.2" + version: "0.0.4" top_snackbar_flutter: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 32cc85b..1270318 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.1.3+7 +version: 1.1.4+8 environment: sdk: '>=2.17.0 <3.0.0' @@ -25,7 +25,7 @@ dependencies: sdk: flutter app_dependencies: path: packages/app_dependencies - ticker_search: ^0.0.2 + ticker_search: ^0.0.4 td_ui: path: packages/td_ui stocks_portfolio: