I have to make a simple study app for a school project, where I want that the user can repeat only the question, which he marked as wrong. Those should be shown as the "original" flipchart. In the class Auswertung I created a button which should have this task. In my Code you just chose one or multiple themes with mulitiple questions each. Than the Flipcharts are shown like they should be. After a specific amount of asnwered questions (currently 2) you get navigated to the overview page, where it should be possible to repeat only the Flipcharts which where marked as wrong.
The following class is for choosing the themes
mport 'package:flutter/material.dart';
import 'package:jagd/widgets/CustomAppBar.item.dart';
import '../../widgets/Baden-Württemberg/Fragen/FlipchartsBW.item.dart';
class FragenBW extends StatefulWidget {
const FragenBW({super.key, required wrongQuestions});
#override
// ignore: library_private_types_in_public_api
_FragenBWState createState() => _FragenBWState();
}
class _FragenBWState extends State<FragenBW> {
String number = '';
final List<String> _themes = [
'Theme 1',
'Theme 2',
'Theme 3',
'Theme 4',
'Theme 5',
'Theme 6',
'Theme 7',
'Theme 8',
];
final List<bool> _selected = List.filled(8, false);
final Map<String, List<Flipchart>> _flipcharts = {
'Theme 1': [
Flipchart(question: 'Question 1', answer: 'Answer 1'),
Flipchart(question: 'Question 1.1', answer: 'Answer 1.2'),
],
'Theme 2': [
Flipchart(question: 'Question 2', answer: 'Answer 2'),
Flipchart(question: 'Question 2.2', answer: 'Answer 2.2'),
],
'Theme 3': [
Flipchart(question: 'Question 3', answer: 'Answer 3'),
Flipchart(question: 'Question 3.2', answer: 'Answer 3.2'),
],
'Theme 4': [
Flipchart(question: 'Question 4', answer: 'Answer 4'),
Flipchart(question: '4.2', answer: 'Answer 4.2'),
],
'Theme 5': [
Flipchart(question: 'Question 5', answer: 'Answer 5'),
Flipchart(question: 'Question 5.2', answer: 'Answer 5.2'),
],
'Theme 6': [
Flipchart(question: 'Question 6', answer: 'Answer 6'),
Flipchart(question: 'Question 6.2', answer: 'Answer 6.2'),
],
'Theme 7': [
Flipchart(question: 'Question 7', answer: 'Answer 7'),
Flipchart(question: 'Question 7.2', answer: 'Answer 7.2'),
],
'Theme 8': [
Flipchart(question: 'Question 8', answer: 'Answer 8'),
Flipchart(question: 'Question 8.2', answer: 'Answer 8.2'),
],
// Add more flipcharts for each theme
};
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[900],
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: Colors.grey[850],
title: const CustomAppBar(title: "Questions/Answers"),
bottom: const PreferredSize(
preferredSize: Size.fromHeight(10),
child: SizedBox(
height: 10,
),
),
),
body: Column(
children: <Widget>[
for (int i = 0; i < _themes.length; i++)
CheckboxListTile(
value: _selected[i],
onChanged: (bool? value) {
setState(() {
_selected[i] = value ?? false;
});
},
title: Text(
_themes[i],
style: const TextStyle(color: Colors.white),
),
),
const SizedBox(
height: 8,
),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
child: const Text(
'learning',
style: TextStyle(color: Colors.white),
),
onPressed: () {
bool atLeastOneSelected = false;
for (int i = 0; i < _selected.length; i++) {
if (_selected[i]) {
atLeastOneSelected = true;
break;
}
}
if (atLeastOneSelected) {
// Code to navigate to next screen
List<Flipchart> selectedFlipcharts = [];
for (int i = 0; i < _themes.length; i++) {
if (_selected[i]) {
selectedFlipcharts.addAll(_flipcharts[_themes[i]]!);
}
}
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FlipchartBW(
flipcharts: selectedFlipcharts.toList(),
onShowWrongFlipcharts: () {},
),
),
);
}
}),
),
],
));
}
}
class Flipchart {
final String question;
final String answer;
Flipchart({required this.question, required this.answer});
String get getName => question;
String get getContent => answer;
}
class CustomAppBar extends StatelessWidget {
final String title;
const CustomAppBar({
Key? key,
required this.title,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
color: Colors.grey[850],
width: double.infinity,
height: 76,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// IconButton(
// icon: const Icon(
// Icons.arrow_back_ios_new,
// color: Colors.white,
// size: 25,
// ),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
),
),
),
],
),
],
),
),
);
}
}
The next Class is for the flipcharts:
import 'package:flutter/material.dart';
import 'package:jagd/widgets/Baden-W%C3%BCrttemberg/Fragen/Auswertung.item.dart';
import 'package:jagd/widgets/CustomAppBar.item.dart';
import '../../../Pages/Baden-Württemberg/FragenBW.item.dart';
class FlipchartBW extends StatefulWidget {
final List<Flipchart> flipcharts;
final void Function() onShowWrongFlipcharts;
const FlipchartBW(
{Key? key, required this.flipcharts, required this.onShowWrongFlipcharts})
: super(key: key);
#override
// ignore: library_private_types_in_public_api
_FlipchartBWState createState() => _FlipchartBWState();
}
class _FlipchartBWState extends State<FlipchartBW>
with SingleTickerProviderStateMixin {
int currentIndex = 0;
bool showAnswer = false;
int correct = 0;
int wrong = 0;
List<Flipchart> wrongFlipcharts = [];
void rightButtonPressed() {
correct++;
checkAnswers();
}
void wrongButtonPressed() {
wrong++;
wrongFlipcharts.add(widget.flipcharts[currentIndex]);
checkAnswers();
}
void checkAnswers() {
if (correct + wrong == 5) {
// Change Number of Queastions that have to be answered
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Auswertung(
correct: correct,
wrong: wrong,
numberofQuestions: 5,
wrongFlipcharts:
wrongFlipcharts.isEmpty ? const [] : wrongFlipcharts,
),
),
);
}
}
void nextQuestion() {
setState(() {
currentIndex = (currentIndex + 1) % widget.flipcharts.length;
showAnswer = false;
});
}
void previousQuestion() {
setState(() {
if (currentIndex == 0) {
currentIndex = currentIndex;
} else {
currentIndex = (currentIndex - 1 + widget.flipcharts.length) %
widget.flipcharts.length;
}
showAnswer = false;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[900],
appBar: AppBar(
backgroundColor: Colors.grey[850],
title: const CustomAppBar(title: "Questions/Answers"),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(10),
child: SizedBox(
height: 10,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: wrong,
child: Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
),
),
Expanded(
flex: correct,
child: Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(10),
),
),
),
],
),
),
),
),
body: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: double.infinity,
height: 100,
decoration: const BoxDecoration(
color: Colors.green,
),
child: Center(
child: Text(
widget.flipcharts.isNotEmpty
? widget.flipcharts[currentIndex].question
: "",
style: const TextStyle(color: Colors.white, fontSize: 20),
),
),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: Visibility(
visible: !showAnswer,
child: TextButton(
child: const Text(
"Show Answer",
style: TextStyle(color: Colors.white),
),
onPressed: () {
setState(() {
showAnswer = true;
});
},
),
),
),
),
Column(
children: <Widget>[
Visibility(
visible: showAnswer,
child: Container(
width: double.infinity,
height: 200,
decoration: const BoxDecoration(
color: Colors.blue,
),
child: Center(
child: Text(
widget.flipcharts.isNotEmpty
? widget.flipcharts[currentIndex].answer
: "",
style:
const TextStyle(color: Colors.white, fontSize: 20),
),
),
),
),
const SizedBox(height: 20),
],
),
],
),
),
bottomNavigationBar: Container(
height: 100,
decoration: const BoxDecoration(color: Colors.transparent),
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
onPressed: previousQuestion,
child: const Icon(Icons.navigate_before, color: Colors.white),
),
),
const SizedBox(
width: 4,
),
Visibility(
visible: showAnswer,
child: Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
child: const Text("WRONG",
style: TextStyle(color: Colors.red)),
onPressed: () {
setState(() {
wrong++;
});
checkAnswers();
nextQuestion();
},
),
),
),
),
const SizedBox(
width: 4,
),
Visibility(
visible: showAnswer,
child: Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
child: const Text("RIGHT",
style: TextStyle(color: Colors.green)),
onPressed: () {
setState(() {
correct++;
});
checkAnswers();
nextQuestion();
},
),
),
),
),
const SizedBox(
width: 4,
),
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
onPressed: nextQuestion,
child: const Icon(Icons.navigate_next, color: Colors.white),
),
),
],
),
),
),
);
}
}
//------------------------------------------------------------------------------
class CustomAppBar extends StatelessWidget {
final String title;
const CustomAppBar({
Key? key,
required this.title,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
color: Colors.grey[850],
width: double.infinity,
height: 76,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// IconButton(
// icon: const Icon(
// Icons.arrow_back_ios_new,
// color: Colors.white,
// size: 25,
// ),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
),
),
),
],
),
],
),
),
);
}
}
The last part is for the overview and the button for the repeat of the wrong Flipcharts
import 'package:flutter/material.dart';
import '../../../Pages/Baden-Württemberg/FragenBW.item.dart';
import 'FlipchartsBW.item.dart';
class Auswertung extends StatelessWidget {
const Auswertung({
Key? key,
required this.correct,
required this.wrong,
required this.wrongFlipcharts,
required int numberofQuestions,
}) : super(key: key);
final int correct;
final int wrong;
final List<Flipchart> wrongFlipcharts;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.grey[850],
appBar: // here the desired height
AppBar(
title: const CustomAppBar(title: "Overview"),
backgroundColor: Colors.grey[850],
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: double.infinity,
height: 100,
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(7)),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 8),
child: Row(
children: [
Expanded(
flex: 1,
child: Column(
children: [
const Center(
child: Text("Right:",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15.5)),
),
const SizedBox(height: 5),
Center(
child: Text("$correct",
style: const TextStyle(
color: Colors.green,
fontSize: 40,
)),
),
],
),
),
Expanded(
flex: 1,
child: Column(
children: [
const Center(
child: Text("Wrong:",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15.5)),
),
const SizedBox(height: 5),
Center(
child: Text("$wrong",
style: const TextStyle(
color: Colors.red, fontSize: 40)),
),
],
),
),
],
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Container(
height: 50,
width: double.infinity,
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(7)),
),
child: TextButton(
onPressed: () => _showWrongFlipcharts(context),
child: const Text('Repeat Wrong questions',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15.5)),
),
),
),
],
)),
);
}
void _showWrongFlipcharts(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FlipchartBW(
flipcharts: wrongFlipcharts,
onShowWrongFlipcharts: () => _showWrongFlipcharts(context),
),
),
);
}
}
class CustomAppBar extends StatelessWidget {
final String title;
const CustomAppBar({
Key? key,
required this.title,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
color: Colors.grey[850],
width: double.infinity,
height: 76,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// IconButton(
// icon: const Icon(
// Icons.arrow_back_ios_new,
// color: Colors.white,
// size: 25,
// ),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
),
),
),
],
),
],
),
),
);
}
}
I tried what my knowledge can do but I was not able to impelent it the right way
Related
I have to make a simple study app for a school project, where I want that the user can repeat only the question, which he marked as wrong. Those should be shown as the "original" flipchart. In the class Auswertung I created a button which should have this task. In my Code you just chose one or multiple themes with mulitiple questions each. Than the Flipcharts are shown like they should be. After a specific amount of asnwered questions (currently 2) you get navigated to the overview page, where it should be possible to repeat only the Flipcharts which where marked as wrong.
The following class is for choosing the themes
import 'package:flutter/material.dart';
import '../../widgets/Baden-Württemberg/Fragen/FlipchartsBW.item.dart';
class FragenBW extends StatefulWidget {
const FragenBW({super.key, required wrongQuestions});
#override
// ignore: library_private_types_in_public_api
_FragenBWState createState() => _FragenBWState();
}
class _FragenBWState extends State<FragenBW> {
String number = '';
final List<String> _themes = [
'Theme 1',
'Theme 2',
'Theme 3',
'Theme 4',
'Theme 5',
'Theme 6',
'Theme 7',
'Theme 8',
];
final List<bool> _selected = List.filled(8, false);
final Map<String, List<Flipchart>> _flipcharts = {
'Theme 1': [
Flipchart(question: 'Question 1', answer: 'Answer 1'),
Flipchart(question: 'Question 1.1', answer: 'Answer 1.2'),
],
'Theme 2': [
Flipchart(question: 'Question 2', answer: 'Answer 2'),
Flipchart(question: 'Question 2.2', answer: 'Answer 2.2'),
],
'Theme 3': [
Flipchart(question: 'Question 3', answer: 'Answer 3'),
Flipchart(question: 'Question 3.2', answer: 'Answer 3.2'),
],
'Theme 4': [
Flipchart(question: 'Question 4', answer: 'Answer 4'),
Flipchart(question: '4.2', answer: 'Answer 4.2'),
],
'Theme 5': [
Flipchart(question: 'Question 5', answer: 'Answer 5'),
Flipchart(question: 'Question 5.2', answer: 'Answer 5.2'),
],
'Theme 6': [
Flipchart(question: 'Question 6', answer: 'Answer 6'),
Flipchart(question: 'Question 6.2', answer: 'Answer 6.2'),
],
'Theme 7': [
Flipchart(question: 'Question 7', answer: 'Answer 7'),
Flipchart(question: 'Question 7.2', answer: 'Answer 7.2'),
],
'Theme 8': [
Flipchart(question: 'Question 8', answer: 'Answer 8'),
Flipchart(question: 'Question 8.2', answer: 'Answer 8.2'),
],
// Add more flipcharts for each theme
};
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[900],
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: Colors.grey[850],
title: const CustomAppBar(title: "Questions/Answers"),
bottom: const PreferredSize(
preferredSize: Size.fromHeight(10),
child: SizedBox(
height: 10,
),
),
),
body: Column(
children: <Widget>[
for (int i = 0; i < _themes.length; i++)
CheckboxListTile(
value: _selected[i],
onChanged: (bool? value) {
setState(() {
_selected[i] = value ?? false;
});
},
title: Text(
_themes[i],
style: const TextStyle(color: Colors.white),
),
),
const SizedBox(
height: 8,
),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
child: const Text(
'learning',
style: TextStyle(color: Colors.white),
),
onPressed: () {
bool atLeastOneSelected = false;
for (int i = 0; i < _selected.length; i++) {
if (_selected[i]) {
atLeastOneSelected = true;
break;
}
}
if (atLeastOneSelected) {
// Code to navigate to next screen
List<Flipchart> selectedFlipcharts = [];
for (int i = 0; i < _themes.length; i++) {
if (_selected[i]) {
selectedFlipcharts.addAll(_flipcharts[_themes[i]]!);
}
}
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FlipchartBW(
flipcharts: selectedFlipcharts.toList()),
),
);
}
}),
),
],
));
}
}
class Flipchart {
final String question;
final String answer;
Flipchart({required this.question, required this.answer});
String get getName => question;
String get getContent => answer;
}
class CustomAppBar extends StatelessWidget {
final String title;
const CustomAppBar({
Key? key,
required this.title,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
color: Colors.grey[850],
width: double.infinity,
height: 76,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// IconButton(
// icon: const Icon(
// Icons.arrow_back_ios_new,
// color: Colors.white,
// size: 25,
// ),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
),
),
),
],
),
],
),
),
);
}
}
The next Class is for the flipcharts:
import 'package:flutter/material.dart';
import 'package:jagd/widgets/Baden-W%C3%BCrttemberg/Fragen/Auswertung.item.dart';
import 'package:jagd/widgets/CustomAppBar.item.dart';
import '../../../Pages/Baden-Württemberg/FragenBW.item.dart';
class FlipchartBW extends StatefulWidget {
final List<Flipchart> flipcharts;
const FlipchartBW({Key? key, required this.flipcharts}) : super(key: key);
#override
// ignore: library_private_types_in_public_api
_FlipchartBWState createState() => _FlipchartBWState();
}
class _FlipchartBWState extends State<FlipchartBW>
with SingleTickerProviderStateMixin {
int currentIndex = 0;
bool showAnswer = false;
int correct = 0;
int wrong = 0;
List<Flipchart> wrongQuestions = [];
void rightButtonPressed() {
correct++;
checkAnswers();
}
void wrongButtonPressed() {
wrong++;
wrongQuestions.add(widget.flipcharts[currentIndex]);
checkAnswers();
}
void checkAnswers() {
if (correct + wrong == 1) {
// Change Number of Queastions that have to be answered
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Auswertung(
correct: correct,
wrong: wrong,
wrongQuestions: wrongQuestions,
numberofQuestions: 5,
)));
}
}
void nextQuestion() {
setState(() {
currentIndex = (currentIndex + 1) % widget.flipcharts.length;
showAnswer = false;
});
}
void previousQuestion() {
setState(() {
if (currentIndex == 0) {
currentIndex = currentIndex;
} else {
currentIndex = (currentIndex - 1 + widget.flipcharts.length) %
widget.flipcharts.length;
}
showAnswer = false;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[900],
appBar: AppBar(
backgroundColor: Colors.grey[850],
title: const CustomAppBar(title: "Questions/Answers"),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(10),
child: SizedBox(
height: 10,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
flex: wrong,
child: Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
),
),
Expanded(
flex: correct,
child: Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.circular(10),
),
),
),
],
),
),
),
),
body: Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
width: double.infinity,
height: 100,
decoration: const BoxDecoration(
color: Colors.green,
),
child: Center(
child: Text(
widget.flipcharts[currentIndex].question,
style: const TextStyle(color: Colors.white, fontSize: 20),
),
),
),
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: Visibility(
visible: !showAnswer,
child: TextButton(
child: const Text(
"Show Answer",
style: TextStyle(color: Colors.white),
),
onPressed: () {
setState(() {
showAnswer = true;
});
},
),
),
),
),
Column(
children: <Widget>[
Visibility(
visible: showAnswer,
child: Container(
width: double.infinity,
height: 200,
decoration: const BoxDecoration(
color: Colors.blue,
),
child: Center(
child: Text(
widget.flipcharts[currentIndex].answer,
style:
const TextStyle(color: Colors.white, fontSize: 20),
),
),
),
),
const SizedBox(height: 20),
],
),
],
),
),
bottomNavigationBar: Container(
height: 100,
decoration: const BoxDecoration(color: Colors.transparent),
child: Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
onPressed: previousQuestion,
child: const Icon(Icons.navigate_before, color: Colors.white),
),
),
const SizedBox(
width: 4,
),
Visibility(
visible: showAnswer,
child: Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
child: const Text("WRONG",
style: TextStyle(color: Colors.red)),
onPressed: () {
setState(() {
wrong++;
});
checkAnswers();
nextQuestion();
},
),
),
),
),
const SizedBox(
width: 4,
),
Visibility(
visible: showAnswer,
child: Expanded(
flex: 1,
child: Container(
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
child: const Text("RIGHT",
style: TextStyle(color: Colors.green)),
onPressed: () {
setState(() {
correct++;
});
checkAnswers();
nextQuestion();
},
),
),
),
),
const SizedBox(
width: 4,
),
Container(
width: 50,
height: 50,
decoration: BoxDecoration(
border: Border.all(
width: 1.0,
color: Colors.grey[850]!,
style: BorderStyle.solid)),
child: TextButton(
onPressed: nextQuestion,
child: const Icon(Icons.navigate_next, color: Colors.white),
),
),
],
),
),
),
);
}
}
//------------------------------------------------------------------------------
class CustomAppBar extends StatelessWidget {
final String title;
const CustomAppBar({
Key? key,
required this.title,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
color: Colors.grey[850],
width: double.infinity,
height: 76,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// IconButton(
// icon: const Icon(
// Icons.arrow_back_ios_new,
// color: Colors.white,
// size: 25,
// ),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
),
),
),
],
),
],
),
),
);
}
}
The last part is for the overview and the button for the repeat of the wrong Flipcharts
import 'package:flutter/material.dart';
import 'package:jagd/Pages/Baden-W%C3%BCrttemberg/FragenBW.item.dart';
import 'package:jagd/widgets/CustomAppBar.item.dart';
class Auswertung extends StatelessWidget {
const Auswertung(
{super.key,
required this.correct,
required this.wrong,
required int numberofQuestions,
required List<Flipchart> wrongQuestions});
final int correct;
final int wrong;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.grey[850],
appBar: // here the desired height
AppBar(
title: const CustomAppBar(title: "Overview"),
backgroundColor: Colors.grey[850],
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: double.infinity,
height: 100,
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(7)),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 8),
child: Row(
children: [
Expanded(
flex: 1,
child: Column(
children: [
const Center(
child: Text("Right:",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15.5)),
),
const SizedBox(height: 5),
Center(
child: Text("$correct",
style: const TextStyle(
color: Colors.green,
fontSize: 40,
)),
),
],
),
),
Expanded(
flex: 1,
child: Column(
children: [
const Center(
child: Text("Wrong:",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15.5)),
),
const SizedBox(height: 5),
Center(
child: Text("$wrong",
style: const TextStyle(
color: Colors.red, fontSize: 40)),
),
],
),
),
],
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Container(
height: 50,
width: double.infinity,
decoration: const BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.all(Radius.circular(7)),
),
child: TextButton(
onPressed: () {},
child: const Text('Repeat Wrong questions',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 15.5)),
),
),
),
],
)),
);
}
}
class CustomAppBar extends StatelessWidget {
final String title;
const CustomAppBar({
Key? key,
required this.title,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
color: Colors.grey[850],
width: double.infinity,
height: 76,
child: Padding(
padding: const EdgeInsets.fromLTRB(8, 0, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
// IconButton(
// icon: const Icon(
// Icons.arrow_back_ios_new,
// color: Colors.white,
// size: 25,
// ),
// onPressed: () {
// Navigator.pop(context);
// },
// ),
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
title,
style: const TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold),
textAlign: TextAlign.end,
),
),
),
],
),
],
),
),
);
}
}
I tried to save them in a List named wrongQuestions but that does not ork quiet as I expected. ChatGPT could not help me aswell
I am making an app with flutter and in my application I made an hidden drawer by putting 2 pages in a Stack widget and when I click on the menu icon, the homepage gets an offset and the drawer screen becomes visible. On the drawerscreen I have 2 selfmade buttons which are supposede to lead you to another page.
My drawer in my homepage is setup with an AnimatedContainer>Listview>Column>Container as in the code below.
import 'package:flutter/material.dart';
import 'package:paws_up/components/buttons/animated_button.dart';
import 'package:paws_up/components/buttons/category_button.dart';
import 'package:paws_up/pages/product_overview_page.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
#override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
double xOffset = 0;
double yOffset = 0;
double scaleFactor = 1;
bool isDrawerOpen = false;
#override
Widget build(BuildContext context) {
return AnimatedContainer(
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(40)),
duration: const Duration(milliseconds: 250),
transform: Matrix4.translationValues(xOffset, yOffset, 0)
..scale(scaleFactor),
child: ListView(
children: [
Column(
children: [
Container(
margin: const EdgeInsets.symmetric(
horizontal: 20,
),
height: 70,
color: Colors.white,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
isDrawerOpen
? IconButton(
onPressed: () {
setState(() {
xOffset = 0;
yOffset = 0;
scaleFactor = 1;
isDrawerOpen = false;
});
},
icon: const Icon(
Icons.chevron_left_rounded,
color: Color.fromARGB(255, 0, 0, 0),
),
)
: IconButton(
onPressed: () {
setState(() {
xOffset = 230;
yOffset = 150;
scaleFactor = 0.6;
isDrawerOpen = true;
});
},
icon: const Icon(
Icons.menu,
color: Color.fromARGB(255, 0, 0, 0),
),
),
const Text(
'PawsUp',
style: TextStyle(
color: Color(0xff363636),
fontFamily: 'Ubuntu',
fontWeight: FontWeight.bold,
fontSize: 24),
),
Row(
children: [
IconButton(
icon: const Icon(Icons.notifications_outlined,
color: Color(0xff363636)),
onPressed: () {
// do something
},
),
IconButton(
icon: const Icon(Icons.person_outline_rounded,
color: Color(0xff363636)),
onPressed: () {
// do something
},
),
],
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(
vertical: 30,
horizontal: 20,
),
decoration: BoxDecoration(
color: const Color.fromARGB(255, 247, 247, 247),
borderRadius: BorderRadius.circular(8)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
IconButton(
icon: const Icon(FontAwesomeIcons.filter,
color: Color(0xff5891AC)),
onPressed: () {},
),
const Text(
'Search..',
style: TextStyle(
color: Color(0xffCAC9C9),
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 16),
),
],
),
Container(
decoration: BoxDecoration(
color: const Color(0xff5891AC),
borderRadius: BorderRadius.circular(8),
),
child: IconButton(
onPressed: () {},
icon: const Icon(
FontAwesomeIcons.magnifyingGlass,
color: Colors.white,
),
),
),
],
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 20),
height: 140,
decoration: BoxDecoration(
color: const Color(0xffD5E5F4),
borderRadius: BorderRadius.circular(15.0),
),
child: Stack(
children: [
Positioned(
top: 50,
left: 135,
child: ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(0),
topRight: Radius.circular(0),
bottomLeft: Radius.circular(0),
bottomRight: Radius.circular(15)),
child: Image.asset(
'images/Banner_photo.jpg',
height: 90.0,
width: 190.0,
fit: BoxFit.cover,
),
),
),
Positioned(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.fromLTRB(15, 8, 0, 8),
child: Text(
'Join our animal loving community',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 20),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(15, 0, 0, 0),
child: AnimatedButton(
height: 40,
width: 100,
text: 'Join Now',
textColor: const Color(0xffD5E5F4),
buttonColor: Colors.white,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const ProductOverviewPage()),
);
},
),
),
],
),
),
],
),
),
Container(
margin: const EdgeInsets.symmetric(
vertical: 30,
horizontal: 20,
),
child: Column(
children: [
Row(
children: [
const Text(
'Pet Categories',
style: TextStyle(
color: Color(0xff363636),
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
const Spacer(),
TextButton(
onPressed: () {},
child: const Text(
'More Categroies',
style: TextStyle(
color: Color(0xff5891AC), fontFamily: 'Ubuntu'),
),
),
],
),
SizedBox(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
children: const [
CategoryButton(
text: 'Cat',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.cat,
),
CategoryButton(
text: 'Dog',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.dog,
),
CategoryButton(
text: 'Fish',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.fish,
),
CategoryButton(
text: 'Bird',
buttonColor: Colors.white,
selectedButtonColor: Color(0xff5891AC),
contentColor: Color(0xff363636),
selectedContentColor: Colors.white,
isSelected: false,
icon: FontAwesomeIcons.dove,
),
],
),
)
],
),
),
Container(
margin: const EdgeInsets.symmetric(
vertical: 30,
horizontal: 20,
),
child: Column(
children: [
Row(
children: [
const Text(
'Adopt Us',
style: TextStyle(
color: Color(0xff363636),
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
const Spacer(),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
const ProductOverviewPage()),
);
},
child: const Text(
'See All',
style: TextStyle(
color: Color(0xff5891AC), fontFamily: 'Ubuntu'),
),
),
],
),
SizedBox(
height: 50,
child: ListView(
scrollDirection: Axis.horizontal,
children: const [],
),
)
],
),
),
],
),
],
),
);
}
}
The drawerScreen code is as follows:
import 'package:flutter/material.dart';
import 'package:paws_up/components/buttons/drawer_button.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:paws_up/pages/home_page.dart';
import 'package:paws_up/pages/product_overview_page.dart';
class DrawerScreen extends StatefulWidget {
const DrawerScreen({super.key});
#override
State<DrawerScreen> createState() => _DrawerScreenState();
}
class _DrawerScreenState extends State<DrawerScreen> {
#override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(
color: Color(0xffD5E5F4),
),
child: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: const EdgeInsets.symmetric(
vertical: 20,
horizontal: 20,
),
child: Row(
children: [
const CircleAvatar(),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
'Firstname Lastname',
style: TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.bold,
fontSize: 20),
),
Text(
'Location',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontSize: 16),
)
],
),
)
],
),
),
Container(
child: Column(
children: [
DrawerButton(
text: 'Home',
icon: Icons.home,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => HomeScreen()),
);
},
),
DrawerButton(
text: 'Adopt',
icon: FontAwesomeIcons.paw,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ProductOverviewPage()),
);
},
),
// DrawerButton(
// text: 'Donate',
// icon: FontAwesomeIcons.circleDollarToSlot,
// ),
// DrawerButton(
// text: 'Favorites',
// icon: FontAwesomeIcons.solidHeart,
// ),
// DrawerButton(
// text: 'Messages',
// icon: FontAwesomeIcons.solidEnvelope,
// ),
// DrawerButton(
// text: 'Profile',
// icon: FontAwesomeIcons.solidUser,
// ),
],
),
),
Container(
padding: const EdgeInsets.fromLTRB(0, 20, 0, 70),
child: Row(
children: [
// DrawerButton(
// text: 'Settings',
// icon: FontAwesomeIcons.gear,
// ),
// DrawerButton(
// text: 'Log in',
// icon: FontAwesomeIcons.arrowRightToBracket,
// ),
],
),
)
],
),
),
);
}
}
I think the problem lies in the DrawerButton. It is supposed to lead you to different pages but it doesn't. This is my DrawerButton code:
import 'package:flutter/material.dart';
class DrawerButton extends StatefulWidget {
final String text;
final IconData icon;
DrawerButton({
super.key,
required this.text,
required this.icon,
required Null Function() onTap,
});
#override
_DrawerButtonState createState() => _DrawerButtonState();
}
class _DrawerButtonState extends State<DrawerButton>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late double _scale;
#override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 200),
lowerBound: 0.0,
upperBound: 0.1,
)..addListener(() {
setState(() {});
});
}
#override
Widget build(BuildContext context) {
_scale = 1 - _controller.value;
return GestureDetector(
onTapDown: _onTapDown,
onTapUp: _onTapUp,
child: Stack(
children: [
Transform.scale(
scale: _scale,
child: _DrawerButtonUi,
),
],
),
);
}
Widget get _DrawerButtonUi => Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 15),
child: Row(
children: [
Icon(
widget.icon,
color: Colors.white,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: Text(
widget.text,
style: const TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.bold,
fontSize: 16,
),
),
),
],
),
);
void _onTapDown(TapDownDetails details) {
_controller.forward();
}
void _onTapUp(TapUpDetails details) {
_controller.reverse();
}
}
I thought maybe it had something to do with the stack widget I have in the gesturedetector of my DrawerButton. I have tried navigator.of(context).push instead of navigator.push, but that does not seem to make a difference.
But I am not quite sure how I can build that widget differently, keep the animation and have the navigator push work.
Does anybody have a solution?
You need to create a widget variable in order to access on state class.
class DrawerButton extends StatefulWidget {
final String text;
final IconData icon;
final VoidCallback onTap; //this will be used
const DrawerButton({
super.key,
required this.onTap,
And will be called on
void _onTapDown(TapDownDetails details) {
_controller.forward();
widget.onTap();
}
Here my bottom preferredSize (preferredSize: Size.fromHeight(148.0)) in appBar.
This error raised onlu in IOS not in android. I dont know why?
On every tab this error raising, so I thought I got this error by preferredSize.
But how to solve this I am not understanding.
This error raised onlu in IOS not in android. I dont know why?
On every tab this error raising, so I thought I got this error by preferredSize.
But how to solve this I am not understanding.
this is my code
import 'package:flutter/material.dart';
import 'package:showcaseview/showcaseview.dart';
import 'package:url_launcher/url_launcher.dart' as UrlLauncher;
import 'package:dropdown_button2/dropdown_button2.dart';
import 'dart:developer';
import '../../../APIMnager/APIManager.dart';
import '../../../APIMnager/preferences.dart';
import '../../../Constants/constants.dart';
import 'action_page.dart';
import 'holding_page.dart';
import 'overview_page.dart';
import 'report_page.dart';
class PMSListDataPage extends StatelessWidget {
final panNum;
final singlePMSData;
final allPMSListData;
const PMSListDataPage(
{Key? key, this.panNum, this.singlePMSData, this.allPMSListData})
: super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: ShowCaseWidget(
onStart: (index, key) {
log('onStart: $index, $key');
},
onComplete: (index, key) {
log('onComplete: $index, $key');
print("here me");
if (index == 0) {
Preferences.saveData("showCaseCount2", "2");
}
},
blurValue: 1,
builder: Builder(
builder: (context) => PMSListDataPage1(
panNum: panNum,
singlePMSData: singlePMSData,
allPMSListData: allPMSListData)),
autoPlayDelay: const Duration(seconds: 3),
),
);
}
}
class PMSListDataPage1 extends StatefulWidget {
final panNum;
final singlePMSData;
final allPMSListData;
const PMSListDataPage1(
{Key? key, this.panNum, this.singlePMSData, this.allPMSListData})
: super(key: key);
#override
_PMSListDataPage1State createState() => _PMSListDataPage1State();
}
class _PMSListDataPage1State extends State<PMSListDataPage1> {
var selectedValue;
ApiManager apiManager = ApiManager();
final GlobalKey _one = GlobalKey();
final GlobalKey _two = GlobalKey();
final GlobalKey _three = GlobalKey();
final scrollController = ScrollController();
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: DefaultTabController(
length: 4,
child: Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: Icon(Icons.arrow_back_ios_rounded),
onPressed: () {
Navigator.pop(context);
},
tooltip: '',
);
},
),
elevation: 0,
backgroundColor: skyBlue,
title: Text(
"PMS",
style: TextStyle(fontSize: tSize16),
),
actions: [
Row(
children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: IconButton(
icon: Image.asset(
"assets/phone_icon.png",
height: 25,
width: 25,
),
onPressed: () {
UrlLauncher.launch('tel:+91$UserRMNumber');
}))
],
)
],
bottom: PreferredSize(
preferredSize: Size.fromHeight(148.0),
child: Column(
children: [
Container(
color: skyBlue,
height: 90,
child:
nameView(widget.singlePMSData, widget.allPMSListData),
),
Padding(
padding: const EdgeInsets.only(bottom: 10.0),
child: TabBar(
overlayColor:
MaterialStateProperty.all(Colors.transparent),
indicatorColor: Colors.white,
unselectedLabelColor: lightBlue,
onTap: (v) {
searchHoldingsQuery.clear();
FocusScope.of(context).unfocus();
},
indicator: UnderlineTabIndicator(
borderSide: BorderSide(
color: Colors.white,
width: 3.2,
style: BorderStyle.solid),
insets: EdgeInsets.only(left: 30.0, right: 30)),
isScrollable: true,
labelColor: Colors.white,
tabs: [
Tab(
child: Text(
'OVERVIEW',
),
),
Tab(
child: Text(
'HOLDINGS',
),
),
Tab(
child: Text(
'REPORTS',
),
),
Tab(
child: Text(
'ACTIONS',
),
),
],
),
),
],
),
),
),
body:
TabBarView(physics: NeverScrollableScrollPhysics(), children: [
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: OverviewPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: HoldingPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: ReportPage(),
),
Padding(
padding: const EdgeInsets.only(top: 12.0),
child: ActionPage(),
),
]),
)),
);
}
}
extension WidgetExtension on _PMSListDataPage1State {
nameView(singlePMSData, allPMSListData) {
return Padding(
padding: const EdgeInsets.only(left: 20, right: 20, top: 5, bottom: 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Colors.white,
),
child: DropdownButtonHideUnderline(
child: DropdownButton2(
onMenuClose: () {},
onTap: () {},
isExpanded: true,
hint: Row(
children: [
SizedBox(
width: 10,
),
Expanded(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
singlePMSData['name'].toString(),
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 6,
),
Row(
children: [
Text(
'₹ ${singlePMSData["current_value"]}',
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: green2Color,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
width: 10,
),
],
),
],
),
],
),
),
],
),
items: allPMSListData.map<DropdownMenuItem<Object>>((option) {
return DropdownMenuItem(
value: option,
child: Container(
width: double.infinity,
alignment: Alignment.centerLeft,
// padding: const EdgeInsets.fromLTRB(0,8.0,0,6.0),
child: Row(
children: [
SizedBox(
width: 10,
),
Text(
option["name"],
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
],
),
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: lightGreyColor, width: 1)))),
);
}).toList(),
selectedItemBuilder: (con) {
return allPMSListData.map<Widget>((item) {
return Row(
children: [
SizedBox(
width: 10,
),
Expanded(
child: Row(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item['name'].toString(),
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: blackColor,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 6,
),
Row(
children: [
Text(
"₹ ${item["current_value"]}",
style: TextStyle(
fontSize: tSize16,
fontWeight: FontWeight.w600,
color: green2Color,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(
width: 10,
),
],
),
],
),
],
),
),
],
);
}).toList();
},
value: selectedValue,
onChanged: (dynamic value) {
setState(() {
});
},
icon: Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.keyboard_arrow_down,
color: Colors.white,
size: 17,
),
),
iconOnClick: Container(
width: 22,
height: 22,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(3),
color: skyBlue,
),
child: Icon(
Icons.keyboard_arrow_up,
color: Colors.white,
size: 17,
),
),
iconSize: 14,
buttonHeight: 70,
buttonPadding: const EdgeInsets.only(left: 14, right: 14),
buttonDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: lightBlue,
),
color: Colors.white,
),
buttonElevation: 1,
itemHeight: 44,
itemPadding: const EdgeInsets.only(left: 14, right: 14),
dropdownMaxHeight: 200,
dropdownPadding: null,
dropdownDecoration: BoxDecoration(
borderRadius: BorderRadius.circular(14),
color: Colors.white,
),
dropdownElevation: 1,
scrollbarRadius: const Radius.circular(40),
scrollbarThickness: 3,
scrollbarAlwaysShow: false,
// offset: const Offset(-10, 0),
),
),
),
);
}
}
i have Provider model:
class TerminalDataModel with ChangeNotifier{
List<Item> _itemMenu = listItems;
final List<Order> _ordersList = orders;
Order? _currentOrder;
Order? get currentOrder => _currentOrder;
List<Order> get ordersList => _ordersList;
void createOrder() {
_currentOrder = Order(
user: currentUser?.name,
number: 1,
orderStatus: OrderStatus.opened,
time: DateTime.now());
_ordersList.add(_currentOrder!);
notifyListeners();
}
void changeOrder(Order order){
}
}
and two pages: 1. terminal page: on this page I can view my selected order and can change it or change status(paid or for example closed)
class OrderList extends StatelessWidget {
TerminalDataModel terminalDataModel = TerminalDataModel();
OrderList({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: ChangeNotifierProvider<TerminalDataModel>.value(
value: terminalDataModel,
child: OrdersTableView(),
));
}
}
class OrdersTableView extends StatelessWidget {
List<GlobalKey> _key = List.generate(3, (v) => new GlobalKey());
double yPosition = 170;
var provider;
OrdersTableView({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
provider = Provider.of<TerminalDataModel>(context, listen: true);
GlobalKey key = GlobalKey();
return Column(
children: [
Stack(
children: [
Container(
height: 40,
color: Styles.appBarColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [
Container(
height: double.infinity,
width: 50,
color: Styles.blackColor,
child: IconButton(
onPressed: () {
Navigator.pushNamed(context, '/terminal');
},
icon: const Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
)),
Row(
children: [
Text(currentUser?.name ?? '',
style: const TextStyle(
color: Colors.white, fontSize: 18)),
const Icon(
Icons.lock,
color: Colors.white,
),
],
),
],
),
),
SizedBox(
height: 40,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Center(
child: Text('Orders',
style: TextStyle(color: Colors.white, fontSize: 18))),
],
),
),
],
),
Stack(children: [
Container(
height: 50,
width: MediaQuery.of(context).size.width,
color: Styles.blackColor,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
ElevatedButton(
onPressed: () {
Provider.of<TerminalDataModel>(context, listen: false)
.createOrder();
},
child: const Text("New order",
style: TextStyle(color: Colors.white, fontSize: 18)),
),
const SizedBox(
width: 25,
),
TextButton(
key: _key[0],
onPressed: () {},
child: const Text('All Status',
style: const TextStyle(
color: Colors.white, fontSize: 18))),
const SizedBox(
width: 25,
),
TextButton(
key: _key[1],
onPressed: () {},
child: const Text('Wait pay',
style: TextStyle(color: Colors.white, fontSize: 18))),
const SizedBox(
width: 25,
),
TextButton(
key: _key[2],
onPressed: () {},
child: const Text('Payed',
style: TextStyle(color: Colors.white, fontSize: 18))),
],
),
),
),
Positioned(
bottom: -22,
left: yPosition,
child: const Icon(
Icons.arrow_drop_up,
size: 50,
color: Colors.white,
))
]),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Expanded(
flex: 3,
child: Text('Open',
style: TextStyle(color: Colors.black, fontSize: 18))),
Expanded(
flex: 5,
child: Text('Order',
style: TextStyle(color: Colors.black, fontSize: 18))),
Expanded(
flex: 3,
child: Text('Status',
style: TextStyle(color: Colors.black, fontSize: 18))),
Expanded(
flex: 1,
child: Text('Sum',
style: TextStyle(color: Colors.black, fontSize: 18))),
],
),
),
),
const Divider(),
ordersList(provider.ordersList, context),
],
);
}
double getYPositionOfWidget(
GlobalKey key,
) {
RenderBox box = key.currentContext?.findRenderObject() as RenderBox;
Offset position = box.localToGlobal(Offset.zero); //this is global position
double y = position.dy;
return y;
}
Widget ordersList(List<Order> orderList, BuildContext context) {
Column ordersTable = Column(
children: <Widget>[],
);
for (int i = 0; i <= orderList.length - 1; i++) {
ordersTable.children.add(
GestureDetector(
onTap: () {
//Navigator.pushNamed(context, '/terminal',arguments: {'model': provider });
Navigator.push(context, MaterialPageRoute(builder: (contex) {
return Provider<TerminalDataModel>.value(
value: provider, child: PosTerminal());
}));
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: SizedBox(
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 3,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${orderList[i].time!.hour}:${orderList[i].time!.minute}",
style: const TextStyle(
color: Colors.black, fontSize: 18)),
Text(getTimeAgo(orderList[i].time ?? DateTime.now()),
style: const TextStyle(
color: Colors.black, fontSize: 13))
],
)),
const Expanded(
flex: 5,
child: Text('Order',
style: TextStyle(color: Colors.black, fontSize: 18))),
const Expanded(
flex: 3,
child: Text('Status',
style: TextStyle(color: Colors.black, fontSize: 18))),
const Expanded(
flex: 1,
child: Text('Sum',
style: TextStyle(color: Colors.black, fontSize: 18))),
],
),
),
),
),
);
ordersTable.children.add(const Divider());
}
return ordersTable;
}
String getTimeAgo(DateTime dateTime) {
String timeAgo = '';
if (dateTime.hour < DateTime.now().hour) {
timeAgo += "${DateTime.now().hour - dateTime.hour} hours, ";
}
if (dateTime.minute < DateTime.now().minute) {
timeAgo += "${DateTime.now().minute - dateTime.minute} minutes";
}
return timeAgo;
}
}
and 2. order_detale page: there I show a list of orders and can create a new order
class PosTerminal extends StatelessWidget {
PosTerminal({Key? key, }) : super(key: key);
#override
Widget build(BuildContext context) {
print(Provider.of<TerminalDataModel>(context,listen: false).ordersList);
return Scaffold(
backgroundColor: Styles.backgroundColor,
body: ChangeNotifierProvider(
create: (context) => TerminalDataModel(),
child: const PosBody(),
)
);
}
}
class PosBody extends StatelessWidget {
const PosBody({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
double sizeW = MediaQuery.of(context).size.width;
double appBarH = 35;
return Column(
children: [
SizedBox(
width: sizeW,
height: appBarH,
child: Stack(children: [
SizedBox(
width: sizeW,
height: appBarH,
child: Container(
color: Styles.appBarColor,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
ElevatedButton.icon(
onPressed: () {
Navigator.pushNamed(context, '/orders');
},
icon: const Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
label: Text(AppLocalizations.of(context)!.orders,
style: const TextStyle(
color: Colors.white, fontSize: 18)),
style: ElevatedButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
/* Please add this to avoid padding */
elevation: 0,
primary: Colors.transparent,
),
),
SizedBox(
height: appBarH - 3,
width: 100,
child: ElevatedButton(
onPressed: () {},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(
Styles.backgroundColor),
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
const RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
topRight: Radius.circular(4),
))),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
elevation: MaterialStateProperty.all(0),
),
child: Text(
AppLocalizations.of(context)!.order,
style: const TextStyle(
color: Colors.black, fontSize: 18),
),
),
),
],
),
Row(
children: [
const Text("Сергей",
style:
TextStyle(color: Colors.white, fontSize: 18)),
const SizedBox(
width: 5,
),
const Icon(
Icons.lock,
color: Colors.white,
),
ElevatedButton.icon(
onPressed: () {
final action = CupertinoActionSheet(
actions: <Widget>[
CupertinoActionSheetAction(
child: const Text(
"Admin panel",
style:
TextStyle(color: Styles.appBarColor),
),
onPressed: () {
Navigator.pushNamed(
context, '/adminPanel');
},
),
CupertinoActionSheetAction(
child: const Text("Settings",
style: TextStyle(
color: Styles.appBarColor)),
onPressed: () {},
)
],
cancelButton: CupertinoActionSheetAction(
child: const Text(
"Cancel",
style: TextStyle(color: Colors.red),
),
onPressed: () {
Navigator.pop(context);
},
),
);
showCupertinoModalPopup(
context: context,
builder: (context) => action);
},
icon: const Icon(Icons.menu),
label: const Text(""),
style: ElevatedButton.styleFrom(
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
/* Please add this to avoid padding */
elevation: 0,
primary: Colors.transparent,
),
),
],
)
],
),
),
),
SizedBox(
width: sizeW,
height: appBarH,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text("Чек № 2323",
style: TextStyle(color: Colors.white, fontSize: 18)),
],
),
),
]),
),
SizedBox(
height: MediaQuery.of(context).size.height - appBarH,
child: Row(
children: [
Expanded(
flex: 2,
child: Container(
color: Styles.backgroundColor,
child: Column(
children: [
const SizedBox(
height: 25,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Expanded(flex: 4, child: Text("Наименование")),
Expanded(flex: 1, child: Text("Кол-во")),
Expanded(flex: 1, child: Text("Цена")),
Expanded(flex: 1, child: Text("Итого")),
],
),
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 15.0),
child: Divider(
height: 1,
color: Colors.black12,
),
),
SizedBox(
height: MediaQuery.of(context).size.height -
appBarH -
200,
child: Container(),
),
const Divider(
height: 1,
color: Colors.black12,
),
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 25, vertical: 10),
child: Column(
children: [
Row(
children: const [
Text("Итого"),
],
),
const SizedBox(
height: 10,
),
Row(
children: const [
Text("К оплате"),
],
),
Padding(
padding:
const EdgeInsets.symmetric(vertical: 15),
child: SizedBox(
height: 30,
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Colors.green,
),
onPressed: () {},
child: const Text("Pay")),
),
)
],
)),
],
),
),
),
Expanded(
flex: 4,
child: Container(
color: Colors.white,
),
),
],
),
)
],
);
}
}
On the model, I save my orders and when I tap on the order I want to pass an object to the 2nd-page, update it and when I pop my 2nd-page list of orders should be updated. How I can do it?
This code is overflowing in the small devices in a flutter.
I want to make this screen responsive.
I am posting because it's not been solved past 8 days
Below is my main.dart
import 'package:flutter/material.dart';
import 'package:mop_n_maid/utils/route_name.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
const themeColor = Color(0xFF353E58);
class OnboardingPage extends StatefulWidget {
const OnboardingPage({Key? key}) : super(key: key);
#override
_OnboardingPageState createState() => _OnboardingPageState();
}
class _OnboardingPageState extends State<OnboardingPage> {
final controller = PageController();
bool isLastPage = true;
void dispose() {
controller.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.only(bottom: 80),
child: PageView(
controller: controller,
onPageChanged: (index) {
setState(() => isLastPage = index == 3);
},
children: [
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/Helping.jpg',
title: 'What do you look for when hiring a maid?',
),
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/verified.jpg',
title: 'Are your domestic helper verified?',
),
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/changeplan.jpg',
title: 'Changed plans because your maid coming late?',
),
buildPage(
color: Colors.white,
urlImage: 'assets/images/extras/Solution.jpg',
title: 'All Solutions at one stop!',
),
],
),
),
bottomSheet: isLastPage
? TextButton(
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: themeColor,
minimumSize: Size.fromHeight(80),
),
onPressed: () {
Navigator.pushReplacementNamed(context, MyRoutes.loginRoute);
},
child: const Text(
'Get Started',
style: TextStyle(fontSize: 24),
),
)
: Container(
padding: const EdgeInsets.symmetric(horizontal: 10),
height: 80,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
TextButton(
onPressed: () {
controller.jumpToPage(3);
},
child: Text(
'SKIP',
style: TextStyle(color: themeColor),
),
),
Center(
child: SmoothPageIndicator(
controller: controller,
count: 4,
effect: WormEffect(
spacing: 16,
dotColor: Colors.black26,
activeDotColor: themeColor,
),
onDotClicked: (index) => controller.animateToPage(
index,
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
),
),
),
TextButton(
onPressed: () {
controller.nextPage(
duration: Duration(milliseconds: 500),
curve: Curves.easeInOut);
},
child: Text(
'NEXT',
style: TextStyle(
color: themeColor,
),
),
),
],
),
),
);
}
}
Widget buildPage({
required Color color,
required String urlImage,
required String title,
}) {
return Container(
color: color,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: 400,
child: Image.asset(
urlImage,
fit: BoxFit.cover,
width: double.infinity,
),
),
const SizedBox(
height: 64,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Text(
title,
style: TextStyle(
color: themeColor,
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
],
),
);
}
This image is showing my problem in detail
Try this
Widget buildPage({
required Color color,
required String urlImage,
required String title,
}) {
return Container(
color: color,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.4,
child: Image.asset(
urlImage,
fit: BoxFit.cover,
width: double.infinity,
),
),
const SizedBox(
height: 64,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Expanded(
Text(
title,
style: TextStyle(
color: themeColor,
fontSize: 25,
fontWeight: FontWeight.bold,
)),
),
),
],
),
);
}`enter code here`