Related
I need to show the data that I add at the top, but it does not happen, I thought that the data is arranged according to the date it was added to the Firebase Firestore,
I think the data is sorted by document ID
After I almost finished the application, I could not solve this problem, I am not very skilled in Firebase and I did not find the solution
class News extends StatefulWidget {
News({Key? key}) : super(key: key);
#override
State<News> createState() => _NewsState();
}
class _NewsState extends State<News> {
final Stream<QuerySnapshot> data =
FirebaseFirestore.instance.collection('news').snapshots();
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255, 102, 102, 102),
appBar: AppBar(
backgroundColor: Colors.blueAccent,
title: Center(
child: Text(
'أخبار الأنمي',
style: TextStyle(fontSize: 30),
),
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: StreamBuilder<QuerySnapshot>(
stream: data,
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return Text('حدث خطأ');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return Column(
children: [
Center(child: Text('جاري التحميل')),
CircularProgressIndicator()
],
);
}
final anime = snapshot.requireData;
return ListView.builder(
physics: BouncingScrollPhysics(),
padding:
EdgeInsets.only(top: 3, left: 3, right: 3, bottom: 80),
itemCount: anime.size,
itemBuilder: (context, index) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.blue, width: 3),
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 3.5,
spreadRadius: 1,
)
],
),
margin: EdgeInsets.all(5),
child: Row(
children: [
Expanded(
flex: 3,
child: Container(
alignment: Alignment.centerRight,
child: Text(
textDirection: TextDirection.rtl,
'${anime.docs[index]['title']}',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w700),
),
)),
Expanded(
flex: 1,
child: Card(
child: Image.network(
'${anime.docs[index]['image']}',
fit: BoxFit.fill,
height: 120,
),
),
)
],
),
),
],
);
});
})),
);
}
}
Yes, firestore will return base on alphabetically sorting based on document ID.
Use the .orderBy("FieldToOrderBy") to return it in your desired order.
Order and limit data - Firestore
so this is the create quiz interface where the teacher can insert the title of the quiz , the question and the option
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:mr_quiz/DB_helper.dart';
import 'package:random_string/random_string.dart';
import 'DB_helper.dart';
import 'question.dart';
import 'qcm.dart';
import 'choix.dart';
import 'folder.dart';
class Create_Quiz extends StatefulWidget {
#override
_Create_QuizState createState() => _Create_QuizState();
}
class _Create_QuizState extends State<Create_Quiz> {
bool choix = false;
late String question;
late String option;
late String titre;
String qst_id=randomAlphaNumeric(16);
String op_id=randomAlphaNumeric(16);
String qcm_id=randomAlphaNumeric(16);
TextEditingController titre_ctrl=TextEditingController();
TextEditingController qst_ctrl=TextEditingController();
TextEditingController choix_ctrl=TextEditingController();
add_qst(Question question){
DB_helper.instance.insertquestion(question);
print('question ajoutée');
}
add_qcm(Qcm qcm){
DB_helper.instance.insertqcm(qcm);
print('qcm ajouté');
}
add_choix(Choix choix){
DB_helper.instance.insertchoix(choix);
print('choix ajouté');
}
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
fontFamily: 'HindGuntur',
),
debugShowCheckedModeBanner: false,
title: 'Mr.Quiz',
routes: {
'/folder': (BuildContext context) => Folder()},
home: Builder(builder: (context) => Scaffold(
backgroundColor: Colors.white,
resizeToAvoidBottomInset: false,
appBar: AppBar(
backgroundColor: Colors.white,
title: Text('QCM', style: TextStyle(
color: Colors.black, fontWeight: FontWeight.bold),),
centerTitle: true,
elevation: 0.0,
leading: IconButton(icon: Icon(Icons.arrow_back),
onPressed: () {},
color: Colors.deepPurple,),
),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Center(child: Container(
height: 160.0,
width: 650.0,
margin: EdgeInsets.fromLTRB(30, 15, 30, 15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.deepPurple.shade50,),
child: Column(
children: <Widget>[
SizedBox(height: 15.0,),
Text("Entrez le titre du QCM:",
style: TextStyle(fontWeight: FontWeight.bold,),
),
Container(
width: 300.0,
child: TextFormField(
controller: titre_ctrl,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
contentPadding: EdgeInsets.fromLTRB(20, 10, 5,
10),
hintText: 'Titre',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple,),
borderRadius: BorderRadius.circular(30.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple.shade200,),
borderRadius: BorderRadius.circular(30.0),
),
),
),
),
],
),
),
),
SizedBox(height: 20.0,),
Container(
width: 350.0,
child: TextFormField(
controller: qst_ctrl,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 10),
hintText: 'Question ',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple.shade100,),
borderRadius: BorderRadius.circular(30.0),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.deepPurple.shade200,),
borderRadius: BorderRadius.circular(30.0),
),
),
),
),
SizedBox(height: 20.0,),
Row(
children: [
Expanded(
flex: 6,
child: TextFormField(
controller: choix_ctrl,
decoration: InputDecoration(
hintText: "option ",
contentPadding: EdgeInsets.fromLTRB(20, 10, 10, 10),
),
),
),
Flexible(
child: SizedBox(
width: 5,
child: Checkbox(value: choix,
onChanged: (val) {
setState(() {
choix= val!;
});
},
activeColor: Colors.deepPurple,
checkColor: Colors.white,
),
),
)
],
),
Row(
children: <Widget>[
SizedBox(width: 120.0),
Icon(Icons.add_circle_outline, color: Colors.deepPurple,
size: 22.0,),
TextButton(
child: Text(
'ajouter un choix', textAlign: TextAlign.center,
style: TextStyle(
color: Colors.deepPurple, fontSize: 16.0),),
onPressed: () {setState(() {
option=choix_ctrl.text;
});
Choix choice =new Choix(op_id,option,choix);
add_choix(choice);
choix_ctrl.clear();},
),
],
),
SizedBox(height: 30.0,),
Column(
children: <Widget>[
ElevatedButton(style: ElevatedButton.styleFrom(
primary: Colors.deepPurple.shade200,
fixedSize: Size(300.0, 50.0),
elevation: 0.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
),
child:
Text('Ajouter Question',
style: TextStyle(fontSize: 16.0),),
onPressed: () {setState(() {
question=qst_ctrl.text;
});
Question qst =new Question(qst_id,question);
add_qst(qst);
qst_ctrl.clear();},),
SizedBox(height: 20.0,),
ElevatedButton(style: ElevatedButton.styleFrom(
primary: Colors.indigo.shade400,
fixedSize: Size(250.0, 50.0),
elevation: 0.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
),
child:
Text(
'valider mon QCM', style: TextStyle(fontSize: 16.0),),
onPressed: () {setState(() {
titre=titre_ctrl.text;
});
Qcm qcm =new Qcm(qcm_id,titre);
add_qcm(qcm);
Navigator.pushNamed(context, '/folder');
},),
],
),
SizedBox(height: 10.0,),
],),
),
),
)
);
}`
this is the folder interface where the quiz title is displayed
import 'package:flutter/material.dart';
import 'DB_helper.dart';
import'package:mr_quiz/createquiz.dart';
import 'qcm.dart';
import 'package:mr_quiz/question.dart';
import 'package:mr_quiz/choix.dart';
class Folder extends StatefulWidget {
const Folder({Key? key}) : super(key: key);
#override
_FolderState createState() => _FolderState();
}
class _FolderState extends State<Folder> {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
fontFamily: 'HindGuntur',
),
debugShowCheckedModeBanner: false,
title: 'Mes QCM',
home: Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: AppBar(backgroundColor: Colors.deepPurple.shade200,
elevation: 0.0,
centerTitle: true,
title: Text(
"Mes QCM",
style:
TextStyle(
color: Colors.white,
fontWeight: FontWeight.w500,
),
),
),
body:FutureBuilder<List<Qcm>>(
future : DB_helper.instance.qcms(),
builder: (BuildContext context, AsyncSnapshot<List<Qcm>> snapshot) {
if (snapshot.hasData) {
List<Qcm>? qcms = snapshot.data;
return ListView.builder(
itemCount: qcms?.length,
itemBuilder: (context, index){
final qcm = qcms![index];
return Dismissible(key: Key(qcm.qcm_id),
onDismissed: (direction){
setState(() {
DB_helper.instance.deleteprofil(qcm.qcm_id);
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("${qcm.titre} supprimé")));
},
background: Container(color: Colors.red),
child: ProfWidget(qcm: qcm, ));
},
);
} else {
return Center(child: CircularProgressIndicator());
}
}
),
)
);
}
}
class ProfWidget extends StatelessWidget {
const ProfWidget({Key? key, required this.qcm}) : super(key: key);
final Qcm qcm;
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: (){
},
child: Card(
margin: EdgeInsets.all(8),
elevation: 8,
child: Row(
children: [
Padding(
padding: EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.only(bottom: 8),
child: Text(qcm.titre,
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 20)),
),
],
),
)
],
),
),
);
}
}
only the loading indicator is showing could anyone please help me solve this problem , and also can anyone please tell me how to display the data in the playquiz interface , we have a table for each model and they're related to each other with foreign keys but i don't know how to display data from them like i want to display the questions that belong to the same quiz and the options for each question
import 'package:flutter/material.dart';
import 'package:stone_recipe_app/homepage.dart';
import 'package:stone_recipe_app/models/recipe.dart';
import 'package:share_plus/share_plus.dart';
class DetailedScreen extends StatelessWidget {
DetailedScreen({Key? key, required this.recipe, required this.index}) : super(key: key);
List<Recipe>? recipe;
int index;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back_ios),
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
},
),
Text(
'Back',
style: TextStyle(color: Color(0xff007AFF)),
)
],
),
iconTheme: const IconThemeData(color: Color(0xff007AFF)),
title: Center(
child: Text(
recipe![index].recipe_name,
style: TextStyle(color: Colors.black),
),
),
backgroundColor: Colors.white,
elevation: 0,
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: [
Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(200),
),
child: Container(
width: 400,
height: 200,
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(9.0)),
image: DecorationImage(
image: AssetImage("images/cook.jpg"),
fit: BoxFit.cover,
),
boxShadow: [
BoxShadow(
blurRadius: 5,
color: Colors.black,
)
],
),
),
),
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
const Icon(
Icons.file_download_sharp,
color: Colors.blue,
size: 40,
),
const Icon(
Icons.document_scanner,
size: 40,
),
IconButton(
onPressed: () {
Share.share(recipe![index].recipe_prep);
},
icon: const Icon(
Icons.share,
color: Colors.blue,
size: 40,
)),
const Icon(
Icons.favorite,
color: Colors.red,
size: 40,
),
]),
SizedBox(
height: 500,
child: Card(
elevation: 4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
'Ingredients',
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
),
),
Column(
children: [
Text(recipe![index].recipe_ingrdients),
],
),
Center(
child: Text(
'Method',
style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
),
),
Text(
recipe![index].recipe_prep,
style: TextStyle(
fontSize: 20,
),
)
],
),
),
)
],
),
),
);
// Scaffold(
// appBar: AppBar(
// title: Text(recipe![index].recipe_name),
// ),
// body: Center(
// child: SingleChildScrollView(
// child: Column(
// mainAxisSize: MainAxisSize.min,
// children: [
// SelectableText(recipe![index].recipe_cat),
// Text(recipe![index].recipe_prep),
// Text(recipe![index].recipe_id.toString()),
// Text(recipe![index].recipe_ingrdients),
// Text(recipe![index].image_name),
// OutlinedButton(
// onPressed: () {
// Share.share(recipe![index].recipe_prep);
// },
// child: Text('Share'))
// ],
// ),
// ),
// ),
// );
}
}
import 'package:flutter/material.dart';
import 'package:stone_recipe_app/detailedScreen.dart';
import 'package:stone_recipe_app/models/recipe.dart';
import 'package:stone_recipe_app/services/db_services.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
#override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
final dbservice = DataBaseService();
#override
void dispose() {
dbservice.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Recipe App')),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: FutureBuilder<List<Recipe>>(
future: dbservice.getRecipe(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Center(child: CircularProgressIndicator());
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data?.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailedScreen(
recipe: snapshot.data,
index: index,
)));
},
title: Text(snapshot.data![index].recipe_name, style: TextStyle(color: Colors.black)),
// trailing: Text(
// snapshot.data![index].recipe_cat,
// style: TextStyle(color: Colors.black),
// overflow: TextOverflow.fade,
// ),
);
},
);
},
)),
);
}
}
enter image description herei am trying to show data from sqlite db in flutter when user click on country category like india china after user click user navigate to other page which are recipe name related to chine or related to india i am trying to show data from sqlite db in flutter when user click on country category like india china after user click user navigate to other page which are recipe name related to chine or related to india enter image description here
add group_list_view: ^1.1.1 package in your pubspec.yaml file.
try below the example then implement it in your project
import 'package:flutter/material.dart';
import 'package:group_list_view/group_list_view.dart';
import 'package:group_listview_example/app_colors.dart';
void main() => runApp(MyApp());
Map<String, List> _elements = {
'Team A': ['Klay Lewis', 'Ehsan Woodard', 'River Bains'],
'Team B': ['Toyah Downs', 'Tyla Kane'],
'Team C': ['Marcus Romero', 'Farrah Parkes', 'Fay Lawson', 'Asif Mckay'],
'Team D': [
'Casey Zuniga',
'Ayisha Burn',
'Josie Hayden',
'Kenan Walls',
'Mario Powers'
],
'Team Q': ['Toyah Downs', 'Tyla Kane', 'Toyah Downs'],
};
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Group List View Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text('Group List View Demo'),
),
body: GroupListView(
sectionsCount: _elements.keys.toList().length,
countOfItemInSection: (int section) {
return _elements.values.toList()[section].length;
},
itemBuilder: _itemBuilder,
groupHeaderBuilder: (BuildContext context, int section) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8),
child: Text(
_elements.keys.toList()[section],
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
),
);
},
separatorBuilder: (context, index) => SizedBox(height: 10),
sectionSeparatorBuilder: (context, section) => SizedBox(height: 10),
),
),
);
}
Widget _itemBuilder(BuildContext context, IndexPath index) {
String user = _elements.values.toList()[index.section][index.index];
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Card(
elevation: 8,
child: ListTile(
contentPadding:
const EdgeInsets.symmetric(horizontal: 18, vertical: 10.0),
leading: CircleAvatar(
child: Text(
_getInitials(user),
style: TextStyle(color: Colors.white, fontSize: 18),
),
backgroundColor: _getAvatarColor(user),
),
title: Text(
_elements.values.toList()[index.section][index.index],
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w400),
),
trailing: Icon(Icons.arrow_forward_ios),
),
),
);
}
String _getInitials(String user) {
var buffer = StringBuffer();
var split = user.split(" ");
for (var s in split) buffer.write(s[0]);
return buffer.toString().substring(0, split.length);
}
Color _getAvatarColor(String user) {
return AppColors
.avatarColors[user.hashCode % AppColors.avatarColors.length];
}
}
How to get data from static or dynamic list and set to list view or grid view
If you want to convert your list of data into a ListView of widgets you can map the data list to your resultant widget list. Follow the code below:
class TestPage extends StatefulWidget {
#override
_TestPageState createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
List<Data> dataList = [
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
Data(name: "Demo name",date: DateTime.now(),description: "Dummy long description",imageURL: 'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
];
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
width: width,
height: height,
child: ListView(
scrollDirection: Axis.vertical,
children: dataList.map((data){
return Container(
width: width,height: 80,
decoration: BoxDecoration(border: Border(bottom: BorderSide(width: 1.5,color: Colors.black))),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(width: 50,height: 50,decoration: BoxDecoration(image: DecorationImage(image: NetworkImage(data.imageURL))),),
Column(
mainAxisSize: MainAxisSize.max,
children: [
Text(data.name),
Expanded(child: Text(data.description)),
],
),
Text(data.date.toString());
],
),
);
}).toList(),
),
),
);
}
}
class Data {
String name;
String imageURL;
String description;
DateTime date;
Data({this.name,this.imageURL,this.date,this.description});
}
Check the above code based on your requirement.
List dataList = [
Data(
name: "Title",date: "12/03/2021",description: "Description",imageURL:'https://m.files.bbci.co.uk/modules/bbc-morph-sport-seo-meta/1.20.8/images/bbc-sport-logo.png'),
];
#override
Widget build(BuildContext context) {
double width = MediaQuery
.of(context)
.size
.width;
double height = MediaQuery
.of(context)
.size
.height;
return Scaffold(
appBar: new AppBar(
bottomOpacity: 0.0,
elevation: 0.0,
backgroundColor: Color(0xFF104C57),
title: new Text("Notification"),
leading: new IconButton(
icon: new Icon(Icons.arrow_back),
onPressed: () => Navigator.of(context).pop(),
),
),
body: SingleChildScrollView(
child: Container(
child: Card(
margin: EdgeInsets.only(left: 7.0, right: 7.0),
child: Container(
width: width,
height: height,
child: ListView(
scrollDirection: Axis.vertical,
children: dataList.map((data) {
return Container(
margin: EdgeInsets.only(left: 6.0, right: 6.0, top: 10.0),
width: width,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
border: Border.all(
color: Color(0xFFDCDADB),
width: 0.5,
),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 10,
),
Container(
width: 65,
height: 65,
decoration: BoxDecoration(
image: DecorationImage(
image: ExactAssetImage(
'lib/images/notificationicon.png',
),
)),
),
SizedBox(
width: 10,
),
Container(
width: 145,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 20,
),
Text(
data.name,
style: TextStyle(
fontSize: 12.0,
//fontWeight: FontWeight.w700,
color: Color(0xFF75778A),
fontWeight: FontWeight.w500,
),
),
Expanded(
child: Text(
data.description,
style: TextStyle(
fontSize: 12.0,
//fontWeight: FontWeight.w700,
color: Color(0xFF868C9A),
),
)),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
height: 20,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
"Date : ",
style: TextStyle(
fontSize: 12.0,
color: Color(0xFF868C9A),
),
),
Text(
data.date,
style: TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w500,
color: Color(0xFF6A7180),
),
),
],
),
],
),
],
),
);
}).toList(),
),
),
),
width: double.infinity,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(00)),
image: DecorationImage(
image: ExactAssetImage('lib/images/homebg.png'),
fit: BoxFit.fill,
),
),
),
),
);
}
class Data {
String name,imageURL,description,date;
Data({this.name, this.imageURL, this.date, this.description});
}
I created a homepage containing horizontal carousels, and under this carousel I created a vertical scrolling list,
I don't know why, but my vertical list doesn't scroll, can anyone have any idea why? I would like vertical scrolling to scroll through everything, both carousels and lists
my code:
#override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return StoreConnector<AppState, OrdersScreenProps>(
converter: (store) => mapStateToProps(store),
onInitialBuild: (props) => this.handleInitialBuild(props),
builder: (context, props) {
List<Order> data = props.listResponse.data;
bool loading = props.listResponse.loading;
Widget body;
if (loading) {
body = Center(
child: CircularProgressIndicator(),
);
} else {
body =
Container(
height: 150.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: data.length,
itemBuilder: (context, i) {
Order order = data[i];
return GestureDetector(
onTap: () {
props.getOrderDetails(order.id);
Navigator.pushNamed(context, AppRoutes.orderDetails);
},
child: Container(
margin: EdgeInsets.all(5.0),
width: 210.0,
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Positioned(
bottom: 15.0,
child: Container(
height: 120.0,
width: 200.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0.0, 2.0),
blurRadius: 6.0,
),
],
),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
order.title,
style: TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.w600,
letterSpacing: 1.2),
),
Text(
order.city,
style: TextStyle(color: Colors.grey),
)
],
),
),
),
),
],
),
),
);
},
),
),
ListView.separated(
scrollDirection: Axis.vertical,
shrinkWrap: true,
padding: const EdgeInsets.all(10.0),
itemCount: data.length,
separatorBuilder: (context, index) => Divider(),
itemBuilder: (context, i) {
Order order = data[i];
return Card(
child: ListTile(
isThreeLine: true,
contentPadding: EdgeInsets.all(25.0),
leading: CircleAvatar(
child: Icon(Icons.person),
foregroundColor: Colors.white,
backgroundColor: Colors.green),
title: Text(
order.title,
style: TextStyle(
fontSize: 24.0, fontWeight: FontWeight.bold),
),
subtitle: Text(order.city),
trailing: Icon(Icons.arrow_forward_ios),
dense: true,
onTap: () {
props.getOrderDetails(order.id);
Navigator.pushNamed(context, AppRoutes.orderDetails);
},
));
},
)
],
);
}
return Scaffold(
// resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize: Size.fromHeight(height * 0.15),
child: AppBar(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.vertical(bottom: Radius.circular(10))),
title: Image(
image: AssetImage('assets/images/logo.png'),
height: 60.0,
),
],
),
),
body: SingleChildScrollView(child: body,),
),
);
},
);
thanks for any help in advance :)
Try adding physics: ClampingScrollPhysics() or physics: BouncingScrollPhysics() on your second/vertical ListView
Also, your Widget body contains a Container and a ListView.separated widget. Wrap it in a column like below code:
Widget body = Column(
children: <Widget>[
Container(
height: 150.0,
child: ListView.builder(
//rest of your code
),
),
ListView.builder(
physics: ClampingScrollPhysics(),
//rest of your code
),
],
);
Then add it to your Scaffold
return Scaffold(
body: SingleChildScrollView(
child: body,
),
);