Skip to content

Commit

Permalink
Improved card UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ivofernandes committed Dec 14, 2023
1 parent 237b2ee commit e2620a5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/big_picture/ui/big_picture_resume_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions lib/big_picture/ui/resume/strategy_resume_header_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(
Expand Down
46 changes: 39 additions & 7 deletions lib/big_picture/ui/resume/strategy_resume_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,22 +32,24 @@ class StrategyResume extends StatelessWidget {

@override
Widget build(BuildContext context) {
// Accessing the state provider
final BigPictureStateProvider bigPictureState = Provider.of<BigPictureStateProvider>(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,
Expand All @@ -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(
Expand All @@ -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(),
),
),
),
),
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand Down

0 comments on commit e2620a5

Please sign in to comment.