diff --git a/lib/main.dart b/lib/main.dart index a4bce4d..9210bc0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,6 +10,9 @@ import 'package:learn/pages/solar.dart'; import 'package:learn/utils/routes.dart'; import 'package:learn/widgets/drawer.dart'; import 'package:learn/pages/colours.dart'; +import 'package:fluttertoast/fluttertoast.dart'; + +DateTime? currentBackPressTime; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -63,236 +66,255 @@ class _MyHomePageState extends State { bool _isImageClicked3 = false; bool _isImageClicked4 = false; bool _isDarkTheme = false; + + Future _onBackPressed() { + DateTime now = DateTime.now(); + if (currentBackPressTime == null || + now.difference(currentBackPressTime!) > const Duration(seconds: 2)) { + currentBackPressTime = now; + Fluttertoast.showToast( + msg: "Press back again to exit", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + ); + return Future.value(false); + } + return Future.value(true); + } + @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text( - 'Home', - style: TextStyle(fontWeight: FontWeight.bold), - ), - actions: [ - IconButton( - icon: Icon( - _isDarkTheme ? 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); - }, + return WillPopScope( + onWillPop: _onBackPressed, + child: Scaffold( + appBar: AppBar( + title: const Text( + 'Home', + style: TextStyle(fontWeight: FontWeight.bold), ), - ], - ), - body: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.all(38.0), - child: Column( - children: [ - GestureDetector( - onTap: () { - setState(() { - _isImageClicked1 = !_isImageClicked1; - }); - Future.delayed(const Duration(milliseconds: 300), () { - Navigator.pushNamed(context, AllRoutes.atozRoute); - }); - }, - child: AnimatedContainer( - duration: const Duration(milliseconds: 300), - curve: Curves.easeInOut, - height: _isImageClicked1 ? 325 : 350, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - border: Border.all(color: Colors.black, width: 2), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.2), - spreadRadius: 2, - blurRadius: 5, - offset: const Offset(0, 3), + actions: [ + IconButton( + icon: Icon( + _isDarkTheme ? 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); + }, + ), + ], + ), + body: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.all(38.0), + child: Column( + children: [ + GestureDetector( + onTap: () { + setState(() { + _isImageClicked1 = !_isImageClicked1; + }); + Future.delayed(const Duration(milliseconds: 300), () { + Navigator.pushNamed(context, AllRoutes.atozRoute); + }); + }, + child: AnimatedContainer( + duration: const Duration(milliseconds: 300), + curve: Curves.easeInOut, + height: _isImageClicked1 ? 325 : 350, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.black, width: 2), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.2), + spreadRadius: 2, + blurRadius: 5, + offset: const Offset(0, 3), + ), + ], + image: const DecorationImage( + image: AssetImage('assets/images/alphabets.jpg'), + fit: BoxFit.cover, ), - ], - image: const DecorationImage( - image: AssetImage('assets/images/alphabets.jpg'), - fit: BoxFit.cover, ), ), ), - ), - const SizedBox(height: 20), - const Text( - 'ALPHABETS', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), - ), - const Text("Learn A to Z with pronunciation and an example"), - const SizedBox( - height: 20, - ), - GestureDetector( - onTap: () { - setState(() { - _isImageClicked2 = !_isImageClicked2; - }); - Future.delayed(const Duration(milliseconds: 300), () { - Navigator.pushNamed(context, AllRoutes.animalRoute); - }); - }, - child: AnimatedContainer( - duration: const Duration(milliseconds: 300), - curve: Curves.easeInOut, - height: _isImageClicked2 ? 325 : 350, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - border: Border.all(color: Colors.black, width: 2), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.2), - spreadRadius: 2, - blurRadius: 5, - offset: const Offset(0, 3), + const SizedBox(height: 20), + const Text( + 'ALPHABETS', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + const Text("Learn A to Z with pronunciation and an example"), + const SizedBox( + height: 20, + ), + GestureDetector( + onTap: () { + setState(() { + _isImageClicked2 = !_isImageClicked2; + }); + Future.delayed(const Duration(milliseconds: 300), () { + Navigator.pushNamed(context, AllRoutes.animalRoute); + }); + }, + child: AnimatedContainer( + duration: const Duration(milliseconds: 300), + curve: Curves.easeInOut, + height: _isImageClicked2 ? 325 : 350, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.black, width: 2), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.2), + spreadRadius: 2, + blurRadius: 5, + offset: const Offset(0, 3), + ), + ], + image: const DecorationImage( + image: AssetImage('assets/images/animals.jpg'), + fit: BoxFit.cover, ), - ], - image: const DecorationImage( - image: AssetImage('assets/images/animals.jpg'), - fit: BoxFit.cover, ), ), ), - ), - const SizedBox(height: 20), - const Text( - 'ANIMALS', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), - ), - const Text("Learn about animals and their voices"), - const SizedBox( - height: 20, - ), - GestureDetector( - onTap: () { - setState(() { - _isImageClicked3 = !_isImageClicked3; - }); - Future.delayed(const Duration(milliseconds: 300), () { - Navigator.pushNamed(context, AllRoutes.partsRoute); - }); - }, - child: AnimatedContainer( - duration: const Duration(milliseconds: 300), - curve: Curves.easeInOut, - height: _isImageClicked3 ? 325 : 350, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - border: Border.all(color: Colors.black, width: 2), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.2), - spreadRadius: 2, - blurRadius: 5, - offset: const Offset(0, 3), + const SizedBox(height: 20), + const Text( + 'ANIMALS', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + const Text("Learn about animals and their voices"), + const SizedBox( + height: 20, + ), + GestureDetector( + onTap: () { + setState(() { + _isImageClicked3 = !_isImageClicked3; + }); + Future.delayed(const Duration(milliseconds: 300), () { + Navigator.pushNamed(context, AllRoutes.partsRoute); + }); + }, + child: AnimatedContainer( + duration: const Duration(milliseconds: 300), + curve: Curves.easeInOut, + height: _isImageClicked3 ? 325 : 350, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.black, width: 2), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.2), + spreadRadius: 2, + blurRadius: 5, + offset: const Offset(0, 3), + ), + ], + image: const DecorationImage( + image: AssetImage('assets/body/body.jpg'), + fit: BoxFit.cover, ), - ], - image: const DecorationImage( - image: AssetImage('assets/body/body.jpg'), - fit: BoxFit.cover, ), ), ), - ), - const SizedBox(height: 20), - const Text( - 'BODY PARTS', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), - ), - const Text("Know about body parts and their pronunciation."), - const SizedBox(height: 20), - GestureDetector( - onTap: () { - setState(() { - _isImageClicked4 = !_isImageClicked4; - }); - Future.delayed(const Duration(milliseconds: 300), () { - Navigator.pushNamed(context, AllRoutes.birdsRoute); - }); - }, - child: AnimatedContainer( - duration: const Duration(milliseconds: 300), - curve: Curves.easeInOut, - height: _isImageClicked4 ? 325 : 350, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - border: Border.all(color: Colors.black, width: 2), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.2), - spreadRadius: 2, - blurRadius: 5, - offset: const Offset(0, 3), + const SizedBox(height: 20), + const Text( + 'BODY PARTS', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + const Text("Know about body parts and their pronunciation."), + const SizedBox(height: 20), + GestureDetector( + onTap: () { + setState(() { + _isImageClicked4 = !_isImageClicked4; + }); + Future.delayed(const Duration(milliseconds: 300), () { + Navigator.pushNamed(context, AllRoutes.birdsRoute); + }); + }, + child: AnimatedContainer( + duration: const Duration(milliseconds: 300), + curve: Curves.easeInOut, + height: _isImageClicked4 ? 325 : 350, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.black, width: 2), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.2), + spreadRadius: 2, + blurRadius: 5, + offset: const Offset(0, 3), + ), + ], + image: const DecorationImage( + image: AssetImage('assets/images/birds.jpg'), + fit: BoxFit.cover, ), - ], - image: const DecorationImage( - image: AssetImage('assets/images/birds.jpg'), - fit: BoxFit.cover, ), ), ), - ), - const SizedBox(height: 20), - const Text( - 'BIRDS', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), - ), - const Text("Look out for Birds with their sounds."), - - const SizedBox(height: 20), - GestureDetector( - onTap: () { - setState(() { - _isImageClicked4 = !_isImageClicked4; - }); - Future.delayed(const Duration(milliseconds: 300), () { - Navigator.pushNamed(context, AllRoutes.colourRoute); - }); - }, - child: AnimatedContainer( - duration: const Duration(milliseconds: 300), - curve: Curves.easeInOut, - height: _isImageClicked4 ? 325 : 350, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(12), - border: Border.all(color: Colors.black, width: 2), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.2), - spreadRadius: 2, - blurRadius: 5, - offset: const Offset(0, 3), + const SizedBox(height: 20), + const Text( + 'BIRDS', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + const Text("Look out for Birds with their sounds."), + + const SizedBox(height: 20), + GestureDetector( + onTap: () { + setState(() { + _isImageClicked4 = !_isImageClicked4; + }); + Future.delayed(const Duration(milliseconds: 300), () { + Navigator.pushNamed(context, AllRoutes.colourRoute); + }); + }, + child: AnimatedContainer( + duration: const Duration(milliseconds: 300), + curve: Curves.easeInOut, + height: _isImageClicked4 ? 325 : 350, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.black, width: 2), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.2), + spreadRadius: 2, + blurRadius: 5, + offset: const Offset(0, 3), + ), + ], + image: const DecorationImage( + image: AssetImage('assets/images/colours/colors-cover.png'), + fit: BoxFit.cover, ), - ], - image: const DecorationImage( - image: AssetImage('assets/images/colours/colors-cover.png'), - fit: BoxFit.cover, ), ), ), - ), - const SizedBox(height: 20), - const Text( - 'COLOURS', - style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), - ), - const Text("Explore and learn about the colours!"), + const SizedBox(height: 20), + const Text( + 'COLOURS', + style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold), + ), + const Text("Explore and learn about the colours!"), - ], + ], + ), ), ), + drawer: const MyDrawer(), ), - drawer: const MyDrawer(), ); } } diff --git a/lib/pages/atoz.dart b/lib/pages/atoz.dart index e0b1937..d5604e2 100644 --- a/lib/pages/atoz.dart +++ b/lib/pages/atoz.dart @@ -1,3 +1,4 @@ + import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'dart:async'; diff --git a/pubspec.lock b/pubspec.lock index b1ad106..b1849e9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -160,6 +160,14 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + sha256: "81b68579e23fcbcada2db3d50302813d2371664afe6165bc78148050ab94bf66" + url: "https://pub.dev" + source: hosted + version: "8.2.5" google_fonts: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index dddf80e..0e1c10e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: card_swiper: ^3.0.1 flutter_card_swiper: ^7.0.0 adaptive_theme: ^3.6.0 + fluttertoast: ^8.2.5 dev_dependencies: flutter_test: @@ -74,6 +75,7 @@ flutter: - assets/solar/ - assets/images/colours/ + # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware