import 'package:flip_card/flip_card.dart';
import 'package:flutter/material.dart';
import 'package:geeks_for_geeks/AddFlashCardPage.dart';
import 'package:geeks_for_geeks/flashCard.dart';
import 'package:geeks_for_geeks/ques_ans.dart';
// Main HomePage widget that is stateful
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
// Index to track the current
// flashcard being displayed
int _curIndexNum = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey.shade100,
appBar: AppBar(
// AppBar with title and styling
centerTitle: true,
title: Text("Flashcards Learning App",
style: TextStyle(
fontSize: 25,
color: Colors.white,
)),
backgroundColor: Colors.green[700],
toolbarHeight: 70,
elevation: 5,
shadowColor: Colors.green[700],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20))),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// FlipCard widget to display the
// front and back of a flashcard
SizedBox(
width: 300,
height: 300,
child: FlipCard(
direction: FlipDirection.HORIZONTAL,
front:
FlashCardWidget(text: qaList[_curIndexNum].question),
back:
FlashCardWidget(text: qaList[_curIndexNum].answer))),
// Text below the FlipCard
Text("Tap to view Answer", style: TextStyle(fontSize: 15)),
// Row containing buttons to
// navigate between flashcards
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
// Button to show the previous flashcard
ElevatedButton.icon(
onPressed: () {
showPreviousCard();
},
icon: Icon(
Icons.arrow_left,
size: 30,
color: Color(0xFFE4E4E4),
),
label: Text(""),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green[700],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
padding: EdgeInsets.only(
right: 20, left: 25, top: 15, bottom: 15))),
// Button to show the next flashcard
ElevatedButton.icon(
onPressed: () {
showNextCard();
},
icon: Icon(
Icons.arrow_right,
size: 30,
color: Color(0xFFE4E4E4),
),
label: Text(""),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green[700],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
padding: EdgeInsets.only(
right: 20, left: 25, top: 15, bottom: 15)))
],
),
SizedBox(height: 15),
// Button to navigate to the AddFlashcardPage
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddFlashcardPage()));
},
child: Text(
"Add FlashCard",
style: TextStyle(
fontSize: 10,
letterSpacing: 1.0,
fontWeight: FontWeight.bold,
color: Colors.white),
textAlign: TextAlign.center,
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green[700],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
padding: EdgeInsets.only(
right: 20, left: 25, top: 15, bottom: 15))),
])));
}
// Function to show the next flashcard
void showNextCard() {
setState(() {
_curIndexNum = (_curIndexNum + 1 < qaList.length) ? _curIndexNum + 1 : 0;
});
}
// Function to show the previous flashcard
void showPreviousCard() {
setState(() {
_curIndexNum =
(_curIndexNum - 1 >= 0) ? _curIndexNum - 1 : qaList.length - 1;
});
}
}