diff --git a/lib/pages/parts.dart b/lib/pages/parts.dart index 657b5fc..e9b648d 100644 --- a/lib/pages/parts.dart +++ b/lib/pages/parts.dart @@ -1,9 +1,12 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:flutter_card_swiper/flutter_card_swiper.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_tts/flutter_tts.dart'; import 'package:learn/utils/constants.dart'; import 'package:learn/utils/functions.dart'; +import 'package:learn/utils/responsive_screen_provider.dart'; void main() { runApp( @@ -66,85 +69,115 @@ class _PartsPagePageState extends State { body: SafeArea( child: Column( children: [ - Flexible( - child: CardSwiper( - controller: controller, - cardsCount: cards.length, - onSwipe: (prevIndex, currentIndex, direction) { - setState(() { - previousIndices.add(topCardIndex); - topCardIndex = currentIndex ?? 0; - }); - return true; - }, - onUndo: _onUndo, - numberOfCardsDisplayed: 3, - backCardOffset: const Offset(40, 40), - padding: const EdgeInsets.all(24.0), - cardBuilder: ( - context, - index, - horizontalThresholdPercentage, - verticalThresholdPercentage, - ) => - cards[index], + Expanded( + child: ResponsiveScreenProvider.isMobileScreen(context)?CardSwiper( + controller: controller, + cardsCount: cards.length, + onSwipe: (prevIndex, currentIndex, direction) { + setState(() { + previousIndices.add(topCardIndex); + topCardIndex = currentIndex ?? 0; + }); + return true; + }, + onUndo: _onUndo, + numberOfCardsDisplayed: 3, + backCardOffset: const Offset(40, 40), + padding: const EdgeInsets.all(24.0), + cardBuilder: ( + context, + index, + horizontalThresholdPercentage, + verticalThresholdPercentage, + ) => + cards[index], + ) : + Center( + child: SizedBox( + height: MediaQuery.of(context).size.height * 0.4, + width: MediaQuery.of(context).size.height * 0.6, + child: CardSwiper( + controller: controller, + cardsCount: cards.length, + onSwipe: (prevIndex, currentIndex, direction) { + setState(() { + previousIndices.add(topCardIndex); + topCardIndex = currentIndex ?? 0; + }); + return true; + }, + onUndo: _onUndo, + numberOfCardsDisplayed: 3, + backCardOffset: const Offset(40, 40), + padding: const EdgeInsets.all(24.0), + cardBuilder: ( + context, + index, + horizontalThresholdPercentage, + verticalThresholdPercentage, + ) => + cards[index], + ), + ), ), ), - Padding( - padding: const EdgeInsets.all(16.0), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - Text( - cards[topCardIndex].name, - style: const TextStyle( - fontSize: 50, fontWeight: FontWeight.bold), - ), - const SizedBox( - width: 150, - ), - Row( - children: [ - IconButton( - icon: const Icon( - Icons.volume_up, - // color: Colors.black, - size: 40, + Expanded( + child: Padding( + padding: const EdgeInsets.all(16.0), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Text( + cards[topCardIndex].name, + style: const TextStyle( + fontSize: 50, fontWeight: FontWeight.bold), + ), + const SizedBox( + width: 150, + ), + Row( + children: [ + IconButton( + icon: const Icon( + Icons.volume_up, + // color: Colors.black, + size: 40, + ), + onPressed: () { + _speakText(cards[topCardIndex].name); + }, ), - onPressed: () { - _speakText(cards[topCardIndex].name); - }, - ), - const SizedBox( - width: 25, - ), - IconButton( - onPressed: controller.undo, - icon: const Icon( - Icons.rotate_left, - // color: Colors.black, - size: 40, + const SizedBox( + width: 25, ), - ), - ], - ), - const SizedBox(height: 10), - const SizedBox(height: 5), - SizedBox( - height: 200, - child: SingleChildScrollView( - clipBehavior: Clip.hardEdge, - child: Text( - AppFunctions() - .getDescription(cards[topCardIndex].name), - style: const TextStyle( - fontSize: 25, + IconButton( + onPressed: controller.undo, + icon: const Icon( + Icons.rotate_left, + // color: Colors.black, + size: 40, + ), + ), + ], + ), + const SizedBox(height: 10), + const SizedBox(height: 5), + SizedBox( + height: 200, + child: SingleChildScrollView( + clipBehavior: Clip.hardEdge, + child: Text( + AppFunctions() + .getDescription(cards[topCardIndex].name), + style: const TextStyle( + fontSize: 25, + ), ), ), ), - ), - ], + ], + ), ), ), ), @@ -202,10 +235,12 @@ class PartsPageCard extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - SvgPicture.asset( - "assets/body/$name.svg", - width: 250, - height: 250, + Expanded( + child: SvgPicture.asset( + "assets/body/$name.svg", + width: 250, + height: 250, + ), ), const SizedBox(height: 10), ], diff --git a/lib/utils/responsive_screen_provider.dart b/lib/utils/responsive_screen_provider.dart new file mode 100644 index 0000000..c8505a7 --- /dev/null +++ b/lib/utils/responsive_screen_provider.dart @@ -0,0 +1,16 @@ +import 'package:flutter/material.dart'; + +class ResponsiveScreenProvider { + static bool isMobileScreen(BuildContext context) { + return MediaQuery.of(context).size.width < 480; + } + + static bool isTabScreen(BuildContext context) { + return MediaQuery.of(context).size.width > 480 && + MediaQuery.of(context).size.width < 800; + } + + static bool isDesktopScreen(BuildContext context) { + return MediaQuery.of(context).size.width >= 800; + } +}