Skip to content

Commit

Permalink
Merge branch 'VaibhavCodeClub:master' into AppConstants
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav-Kushwaha-1225 authored Jun 5, 2024
2 parents 18bb215 + 9ba1e1d commit ca46a0d
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 143 deletions.
27 changes: 20 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ import 'package:flutter/material.dart';
import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:learn/landing_page.dart';
import 'package:learn/utils/route/routes.dart';
import 'package:learn/theme_provider.dart';
import 'package:provider/provider.dart';

DateTime? currentBackPressTime;

void main() async {
WidgetsFlutterBinding.ensureInitialized();
final savedThemeMode = await AdaptiveTheme.getThemeMode();
runApp(MyApp(savedThemeMode: savedThemeMode));
runApp(
ChangeNotifierProvider(
create: (context) => ThemeProvider(),
child: MyApp(savedThemeMode: savedThemeMode),
),
);
}

class MyApp extends StatelessWidget {
Expand All @@ -18,12 +25,18 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Learn',
themeMode: ThemeMode.system,
home: LandingPage(),
onGenerateRoute: Routers.generateRoute,
return Consumer<ThemeProvider>(
builder: (context, themeProvider, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Learn',
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: themeProvider.themeMode,
home: const LandingPage(),
onGenerateRoute: Routers.generateRoute,
);
},
);
}
}
51 changes: 45 additions & 6 deletions lib/pages/explore/explore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:learn/pages/explore/quiz.dart';
import 'package:learn/pages/modules/atoz.dart';
import 'package:learn/pages/modules/birds.dart';
import 'package:learn/pages/modules/colours.dart';
import 'package:learn/pages/modules/planets.dart';
import 'package:learn/pages/modules/shapes.dart';
import 'package:learn/utils/constants.dart';
import 'package:learn/utils/route/route_constant.dart';

import '../../utils/const_dimensions.dart';

// Explore Page
class ExplorePage extends StatelessWidget {
class ExplorePage extends StatefulWidget {
const ExplorePage({super.key});

@override
State<ExplorePage> createState() => _ExplorePageState();
}

class _ExplorePageState extends State<ExplorePage> {
@override
Widget build(BuildContext context) {
return SafeArea(
Expand All @@ -33,7 +44,7 @@ class ExplorePage extends StatelessWidget {
[
GestureDetector(
onTap: () {
Navigator.pushNamed(context, '/quiz');
Navigator.push(context, (MaterialPageRoute(builder: (context) => const QuizPage())));
},
child: Container(
margin: const EdgeInsets.all(5.0),
Expand Down Expand Up @@ -105,10 +116,38 @@ class ExplorePage extends StatelessWidget {
delegate: SliverChildBuilderDelegate(
(context, index) {
return GestureDetector(
onTap: () => Navigator.push(
context,
AppConstants.modules[index].route,
),
onTap: () {
try{
switch (index) {
case 0:
Navigator.push(context, (MaterialPageRoute(builder: (context) => const QuizPage())));
break;
case 1:
Navigator.push(context, (MaterialPageRoute(builder: (context) => const AtoZ())));
break;
case 2:
Navigator.push(context, (MaterialPageRoute(builder: (context) => BirdsPage())));
break;
case 3:
Navigator.push(context, (MaterialPageRoute(builder: (context) => const ColoursPage())));
break;
case 4:
Navigator.push(context, (MaterialPageRoute(builder: (context) => BirdsPage())));
break;
case 5:
Navigator.push(context, (MaterialPageRoute(builder: (context) => const ShapesPage())));
break;
case 6:
Navigator.push(context, (MaterialPageRoute(builder: (context) => PlanetsPage())));
break;
default:
break;
}
}
catch (e) {
print(e);
}
},
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 24, vertical: 12),
Expand Down
26 changes: 8 additions & 18 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// ignore_for_file: deprecated_member_use

import 'package:adaptive_theme/adaptive_theme.dart';
import 'package:flutter/material.dart';
import 'package:learn/utils/assets_path.dart';
import 'package:learn/utils/const_dimensions.dart';
import 'package:learn/utils/route/route_constant.dart';
import 'package:provider/provider.dart';
import '../widgets/drawer.dart';
import '../theme_provider.dart';

class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
Expand All @@ -16,10 +16,10 @@ class MyHomePage extends StatefulWidget {

class _MyHomePageState extends State<MyHomePage> {
final List<bool> _isImageClicked = List.generate(7, (index) => false);
bool _isDarkTheme = false;

@override
Widget build(BuildContext context) {
final themeProvider = Provider.of<ThemeProvider>(context);
return Scaffold(
appBar: AppBar(
title: const Text(
Expand All @@ -31,17 +31,10 @@ class _MyHomePageState extends State<MyHomePage> {
padding: const EdgeInsets.only(right: 16, top: 1),
child: IconButton(
icon: Icon(
_isDarkTheme ? Icons.dark_mode : Icons.light_mode,
themeProvider.themeMode == ThemeMode.dark ? Icons.dark_mode : Icons.light_mode,
),
onPressed: () {
setState(() {
_isDarkTheme = !_isDarkTheme;
});
final themeMode =
Theme.of(context).brightness == Brightness.dark
? AdaptiveThemeMode.light
: AdaptiveThemeMode.dark;
AdaptiveTheme.of(context).setThemeMode(themeMode);
themeProvider.toggleTheme();
},
),
),
Expand All @@ -56,8 +49,7 @@ class _MyHomePageState extends State<MyHomePage> {
context: context,
title: "ALPHABETS",
image: AssetsPath.getAlphabetImage(Alphabets.alphabets),
shortDescription:
"Learn A to Z with pronunciation and an example",
shortDescription: "Learn A to Z with pronunciation and an example",
route: AllRoutesConstant.atozRoute,
index: 0,
),
Expand All @@ -79,8 +71,7 @@ class _MyHomePageState extends State<MyHomePage> {
context: context,
title: "BODY PARTS",
image: AssetsPath.getBodyImage(Body.body),
shortDescription:
"Know about body parts and their pronunciation.",
shortDescription: "Know about body parts and their pronunciation.",
route: AllRoutesConstant.partsRoute,
index: 2,
),
Expand Down Expand Up @@ -124,8 +115,7 @@ class _MyHomePageState extends State<MyHomePage> {
context: context,
title: "FRUITS & VEGETABLES",
image: 'assets/fruitsVeges/cover.jpg',
shortDescription:
"Explore and learn about Fruits and Vegetables!",
shortDescription: "Explore and learn about Fruits and Vegetables!",
route: AllRoutesConstant.fruitRoute,
index: 6,
),
Expand Down
28 changes: 14 additions & 14 deletions lib/pages/modules/animals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import 'package:learn/utils/constants.dart';
import '../../utils/const_dimensions.dart';

class AnimalsPage extends StatelessWidget {


final FlutterTts flutterTts = FlutterTts();
final AudioPlayer audioPlayer = AudioPlayer();

Expand All @@ -31,7 +29,7 @@ class AnimalsPage extends StatelessWidget {
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
_showAnimalPopup(context, AppConstants.animals[index],index);
_showAnimalPopup(context, AppConstants.animals[index], index);
},
child: Container(
margin: const EdgeInsets.all(5.0),
Expand All @@ -46,7 +44,8 @@ class AnimalsPage extends StatelessWidget {
SizedBox(
width: ConstantDimensions.widthExtraLarge,
height: ConstantDimensions.heightExtraLarge,
child: SvgPicture.asset(AppConstants.animals[index].svgAsset),
child:
SvgPicture.asset(AppConstants.animals[index].svgAsset),
),
const SizedBox(width: ConstantDimensions.widthMedium_Large),
Text(
Expand All @@ -66,7 +65,8 @@ class AnimalsPage extends StatelessWidget {
);
}

Future<void> _showAnimalPopup(BuildContext context, Animal animal, int currentIndex) async {
Future<void> _showAnimalPopup(
BuildContext context, Animal animal, int currentIndex) async {
await flutterTts.setVolume(1.0);
await flutterTts.setSpeechRate(.5);
await flutterTts.setLanguage("EN-IN");
Expand Down Expand Up @@ -140,13 +140,11 @@ class _AnimalPopupState extends State<AnimalPopup> {
isTapped = !isTapped;
});
},
child: SizedBox(
width: ConstantDimensions.widthExtraLarge * 4,
height: ConstantDimensions.heightExtraLarge * 4,
child: SvgPicture.asset(
widget.animal.svgAsset,
color: isTapped ? const Color.fromARGB(81, 118, 96, 94) : null,
),
child: SvgPicture.asset(
widget.animal.svgAsset,
color: isTapped ? const Color.fromARGB(81, 118, 96, 94) : null,
width: MediaQuery.of(context).size.width * 0.3,
height: MediaQuery.of(context).size.height * 0.3,
),
),
const SizedBox(height: ConstantDimensions.heightSmall_Medium),
Expand All @@ -157,12 +155,14 @@ class _AnimalPopupState extends State<AnimalPopup> {
child: const Text('Play Sound'),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
_navigateToPreviousAnimal();
},
icon: const Icon(Icons.arrow_back),
iconSize: 30,
),
SizedBox(
width: ConstantDimensions.exceptions[0],
Expand All @@ -172,6 +172,7 @@ class _AnimalPopupState extends State<AnimalPopup> {
_navigateToNextAnimal();
},
icon: const Icon(Icons.arrow_forward),
iconSize: 30,
),
],
)
Expand All @@ -195,7 +196,7 @@ class _AnimalPopupState extends State<AnimalPopup> {
);
}

void _navigateToPreviousAnimal() {
void _navigateToPreviousAnimal() {
setState(() {
widget.currentIndex = (widget.currentIndex - 1) % widget.animals.length;
if (widget.currentIndex < 0) {
Expand All @@ -212,7 +213,6 @@ void _navigateToPreviousAnimal() {
});
}


Future<void> _playAnimalSound(String soundAsset) async {
await widget.audioPlayer.setAsset(soundAsset);
await widget.audioPlayer.play();
Expand Down
Loading

0 comments on commit ca46a0d

Please sign in to comment.