Drawing a circle with draw line flutter - android

Hi I am attempting to draw a circle with just the drawLine() canvas methods in flutter to make a circle which looks something like this:
image of dashed circle
This is to make a speed gauge in my app and I would like to do this without using any additional dependencies if possible.
Any help is appreciated, Thanks

You can directly use / fork or reference source code of https://pub.dev/packages/flutter_gauge
github source code https://github.com/alitorki2651/flutter_gauge/tree/master/lib
working demo
full example code
import 'package:flutter/material.dart';
import 'package:flutter_gauge/flutter_gauge.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 60),
child: FlutterGauge(
index: 50,
hand: Hand.short,
number: Number.endAndCenterAndStart,
secondsMarker: SecondsMarker.secondsAndMinute,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
),
),
),
Row(
children: <Widget>[
Expanded(
child: FlutterGauge(
index: 50,
hand: Hand.short,
number: Number.endAndCenterAndStart,
secondsMarker: SecondsMarker.secondsAndMinute,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
),
),
),
// Expanded(child: FlutterGauge(secondsMarker: SecondsMarker.none,hand: Hand.short,number: Number.none,width: 200,index: 38.0,fontFamily: "Iran",counterStyle: TextStyle(color: Colors.black,fontSize: 35),counterAlign: CounterAlign.center,isDecimal: false),),
],
),
Row(
children: <Widget>[
Expanded(
child: FlutterGauge(
handSize: 30,
width: 200,
index: 50.0,
fontFamily: "Iran",
end: 100,
number: Number.endAndCenterAndStart,
secondsMarker: SecondsMarker.secondsAndMinute,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
)),
),
// Expanded(child: FlutterGauge(secondsMarker: SecondsMarker.none,hand: Hand.short,number: Number.none,width: 200,index: 38.0,fontFamily: "Iran",counterStyle: TextStyle(color: Colors.black,fontSize: 35),counterAlign: CounterAlign.center,isDecimal: false),),
],
),
Row(
children: <Widget>[
Expanded(
child: FlutterGauge(
handSize: 30,
width: 200,
index: 80.0,
fontFamily: "Iran",
end: 100,
number: Number.endAndCenterAndStart,
secondsMarker: SecondsMarker.secondsAndMinute,
hand: Hand.short,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 22,
)),
),
// Expanded(child: FlutterGauge(handSize: 30,width: 200,index: 65.0,fontFamily: "Iran",end: 500,number: Number.endAndStart,secondsMarker: SecondsMarker.minutes,isCircle: false,counterStyle: TextStyle(color: Colors.black,fontSize: 25,)),),
],
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.black38,
child: FlutterGauge(
inactiveColor: Colors.white38,
activeColor: Colors.white,
handSize: 30,
width: 200,
index: 65.0,
fontFamily: "Iran",
end: 400,
number: Number.none,
secondsMarker: SecondsMarker.minutes,
isCircle: false,
hand: Hand.none,
counterAlign: CounterAlign.center,
counterStyle: TextStyle(
color: Colors.white,
fontSize: 30,
),
isDecimal: false,
)),
),
// Expanded(child: FlutterGauge(width: 200,index: 67.3,fontFamily: "Iran",counterStyle: TextStyle(color: Colors.black,fontSize: 35,),numberInAndOut: NumberInAndOut.outside,counterAlign: CounterAlign.center,secondsMarker: SecondsMarker.secondsAndMinute,hand: Hand.short,),),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: FlutterGauge(
index: 50.0,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
),
widthCircle: 10,
secondsMarker: SecondsMarker.none,
number: Number.all),
),
// Expanded(child: FlutterGauge(index: 25.0,counterStyle : TextStyle(color: Colors.black,fontSize: 25,),secondsMarker: SecondsMarker.secondsAndMinute,number: Number.all,numberInAndOut: NumberInAndOut.outside,)),
],
),
Row(
children: <Widget>[
// Expanded(child: FlutterGauge(handSize: 30,width: 200,index: 65.0,fontFamily: "Iran",end: 100,number: Number.endAndCenterAndStart,secondsMarker: SecondsMarker.secondsAndMinute,counterStyle: TextStyle(color: Colors.black,fontSize: 25,)),),
// Expanded(child: FlutterGauge(secondsMarker: SecondsMarker.none,hand: Hand.short,number: Number.none,width: 200,index: 38.0,fontFamily: "Iran",counterStyle: TextStyle(color: Colors.black,fontSize: 35),counterAlign: CounterAlign.center,isDecimal: false),),
],
),
Row(
children: <Widget>[
Expanded(
child: FlutterGauge(
handSize: 30,
width: 200,
index: 80.0,
fontFamily: "Iran",
end: 100,
number: Number.endAndCenterAndStart,
secondsMarker: SecondsMarker.secondsAndMinute,
hand: Hand.short,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 22,
)),
),
// Expanded(child: FlutterGauge(handSize: 30,width: 200,index: 65.0,fontFamily: "Iran",end: 500,number: Number.endAndStart,secondsMarker: SecondsMarker.minutes,isCircle: false,counterStyle: TextStyle(color: Colors.black,fontSize: 25,)),),
],
),
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.black38,
child: FlutterGauge(
inactiveColor: Colors.white38,
activeColor: Colors.white,
handSize: 30,
width: 200,
index: 65.0,
fontFamily: "Iran",
end: 400,
number: Number.none,
secondsMarker: SecondsMarker.minutes,
isCircle: false,
hand: Hand.none,
counterAlign: CounterAlign.center,
counterStyle: TextStyle(
color: Colors.white,
fontSize: 30,
),
isDecimal: false,
)),
),
// Expanded(child: FlutterGauge(width: 200,index: 67.3,fontFamily: "Iran",counterStyle: TextStyle(color: Colors.black,fontSize: 35,),numberInAndOut: NumberInAndOut.outside,counterAlign: CounterAlign.center,secondsMarker: SecondsMarker.secondsAndMinute,hand: Hand.short),),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: FlutterGauge(
index: 50.0,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
),
widthCircle: 10,
secondsMarker: SecondsMarker.none,
number: Number.all),
),
// Expanded(child: FlutterGauge(index: 25.0,counterStyle : TextStyle(color: Colors.black,fontSize: 25,),secondsMarker: SecondsMarker.secondsAndMinute,number: Number.all,numberInAndOut: NumberInAndOut.outside,)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
child: FlutterGauge(
index: 50.0,
width: 270,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
),
widthCircle: 10,
secondsMarker: SecondsMarker.none,
number: Number.all),
),
],
),
FlutterGauge(
handSize: 30,
width: 270,
index: 65.0,
fontFamily: "Iran",
end: 100,
number: Number.endAndCenterAndStart,
secondsMarker: SecondsMarker.secondsAndMinute,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
)),
FlutterGauge(
index: 50.0,
width: 270,
counterStyle: TextStyle(
color: Colors.black,
fontSize: 25,
),
widthCircle: 10,
secondsMarker: SecondsMarker.none,
number: Number.all),
],
),
);
}
}

Related

The Tab-bar View Issues

Tab bar View
The Issues Which is if I try to add tab bar view it show Horizontal viewport was given unbounded height is there any other alternate for tab bar view to fix this issues
GitHub Link : https://github.com/RakulAgn/MyFlutterApp/blob/master/ui/lib/Pages/LandingPage.dart
Hi i checked your code you need to wrap your Scaffold with the DefaultTabController and then move forward to show tabs and tabview. I'm attaching the code for your reference please check.
return DefaultTabController(
length: 3,
child: Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
// child: Center(
child: Column(children: [
Expanded(
flex: 5,
child: Container(
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: 15,
),
Row(
children: [
SizedBox(height: 80),
customIconGoBack(context),
Row(
children: [
SizedBox(
width: 230,
),
customIconFav(),
],
)
],
)
],
),
SizedBox(
height: 280,
),
Row(
children: [
SizedBox(
height: 10,
width: 20,
),
Icon(
Icons.location_on_sharp,
color: Colors.white,
size: 25,
),
SizedBox(
width: 2,
),
Text(
"2.4km away",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 12,
color: Colors.white,
),
),
],
),
SizedBox(
height: 5,
),
Row(
children: [
SizedBox(
height: 5,
width: 20,
),
Container(
child: Text(
'Bondi Beach',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24,
color: Colors.white,
),
),
),
SizedBox(
width: 110,
),
Container(
height: 30,
margin: EdgeInsets.only(right: 20),
padding: EdgeInsets.only(left: 10),
width: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.black45,
),
child: Row(
children: [
Icon(
Icons.star_rounded,
color: Colors.white,
size: 25,
),
SizedBox(
width: 2,
),
Text(
"4.9",
style: TextStyle(color: Colors.white),
)
],
),
)
],
)
],
),
margin:
EdgeInsets.only(right: 18, left: 18, top: 15, bottom: 15),
padding: EdgeInsets.only(bottom: 15, top: 15),
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.5), BlendMode.dstOver),
image: AssetImage('./Assets/Bondi.jpg'),
),
boxShadow: [
BoxShadow(
color: Colors.black12,
offset: Offset(2, 2), //(x,y)
blurRadius: 5.0,
)
],
borderRadius: BorderRadius.circular(10),
),
height: MediaQuery.of(context).size.height / 1.7,
),
),
Container(
// height: 50,
child: Theme(
data: ThemeData(
splashColor: Colors.transparent,
highlightColor: Colors.transparent),
child: TabBar(
labelColor: Colors.black,
unselectedLabelColor: Colors.grey,
indicatorPadding: EdgeInsets.only(right: 16),
labelPadding: EdgeInsets.only(right: 16),
indicator: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(5)),
tabs: [
Tab(
text: "Overview",
),
Tab(
text: "Reviews",
),
Tab(
text: "Friends",
),
],
),
),
),
Expanded(
child: TabBarView(
children: <Widget>[
Center(
child: Text("It's cloudy here",
style: textStyleRoboto(
textColor: ColorTheme.blackColor,
)),
),
Center(
child: Text("It's rainy here"),
),
Center(
child: Text("It's sunny here"),
),
],
),
),
]),
),
),
)),
);

Flutter Swipe Cards Lagging and Swiping is too slow what is the solution to make it fast?

I am building a tinder and bumble like dating app in a flutter. So, I am using swipe cards and as I have to make it scrollable so when I make it scrollable then the swiping is too slow and there is so much lagging so is there any solution to get rid of it?
Here is my code:
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:swipe_cards/swipe_cards.dart';
class HomeScreen extends StatefulWidget {
#override
_HomeScreenState createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
List<String> _images = [
"https://images.unsplash.com/photo-1594744803329-e58b31de8bf5?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80",
"https://static01.nyt.com/images/2019/11/17/books/review/17Salam/Salam1-superJumbo.jpg",
"https://images.unsplash.com/photo-1488426862026-3ee34a7d66df?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80",
"https://images.unsplash.com/photo-1508214751196-bcfd4ca60f91?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80",
"https://images.unsplash.com/photo-1488716820095-cbe80883c496?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=333&q=80",
"https://images.unsplash.com/photo-1485043433441-db091a258e5a?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=334&q=80"
];
List<SwipeItem> _swipeItems = [];
MatchEngine? _matchEngine;
#override
void initState() {
// TODO: implement initState
for (int i = 0; i < _images.length; i++) {
_swipeItems.add(SwipeItem(content: _images[i]));
}
_matchEngine = MatchEngine(swipeItems: _swipeItems);
super.initState();
}
#override
Widget build(BuildContext context) {
double screenWidth = MediaQuery.of(context).size.width;
double screenHeight = MediaQuery.of(context).size.height;
return Scaffold(
//backgroundColor: Color(0xff7cc8cc),
appBar: AppBar(
backgroundColor: Color(0xff76c9b2),
centerTitle: true,
title: Text('Flutter Tinder Cards'),
),
body: SwipeCards(
matchEngine: _matchEngine!,
onStackFinished: () {},
itemBuilder: (context, index) {
return Container(
height: screenHeight,
width: screenWidth,
child: Card(
margin: EdgeInsets.all(0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(0)),
side: BorderSide(color: Colors.grey)
),
child: SingleChildScrollView(
child: Column(
children: [
CachedNetworkImage(
placeholder: (context, url) =>
Center(child: CircularProgressIndicator()),
height: screenHeight,
width: screenWidth,
fit: BoxFit.cover,
//imageUrl: imgUrls![0],
imageUrl: _images[0],
),
Padding(
padding: const EdgeInsets.only(
left: 23.0,
top: 12,
bottom: 12,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
'Poonam, 18',
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.w700,
color: Colors.black87),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 23,
),
child: Row(
children: [
Icon(
Icons.location_on_sharp,
size: 20,
),
SizedBox(
width: 4,
),
Text(
'Surat, India',
style: TextStyle(
fontSize: 18,
),
),
],
),
),
Padding(
padding: const EdgeInsets.only(
top: 12, left: 23, right: 22, bottom: 8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Personal Information',
style: TextStyle(
fontWeight: FontWeight.w700, fontSize: 18),
),
SizedBox(
height: 6,
),
Text(
'Ex - Zerodha, Ex - Grant Thornton. I used to crunch numbers and value companies for a living, now I’m trying to build one.',
style: TextStyle(fontSize: 12),
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
children: [
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Height',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
"5'11",
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
),
SizedBox(width: 20),
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Community',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Vaishnav',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
)
],
),
),
SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
children: [
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Gender',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Female',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
),
SizedBox(width: 20),
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Workout',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Regularly',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
)
],
),
),
SizedBox(
height: 30,
),
//imgUrls![1] == ''
Container(
height: 569,
child: CachedNetworkImage(
placeholder: (context, url) =>
CircularProgressIndicator(),
fit: BoxFit.cover,
//imageUrl: imgUrls![1],
imageUrl: _images[1],
),
),
Padding(
padding: const EdgeInsets.only(
top: 12, left: 23, right: 22, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
'Professional Information',
style: TextStyle(
fontWeight: FontWeight.w700, fontSize: 18),
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
children: [
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Education',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Master Degree',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
),
SizedBox(width: 20),
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Worklife',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
)
],
),
),
SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
children: [
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Salary',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Above 10Lpa',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
)
],
),
),
SizedBox(
height: 30,
),
//imgUrls![2] == ''
Container(
height: 569,
child: CachedNetworkImage(
placeholder: (context, url) =>
CircularProgressIndicator(),
fit: BoxFit.cover,
//imageUrl: imgUrls![2],
imageUrl: _images[2],
),
),
Padding(
padding: const EdgeInsets.only(
top: 12, left: 23, right: 22, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
'Social Life',
style: TextStyle(
fontWeight: FontWeight.w700, fontSize: 18),
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
children: [
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Drinking',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Never',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
),
SizedBox(width: 20),
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Smoking',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Never',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
)
],
),
),
SizedBox(
height: 30,
),
Container(
height: 569,
child: CachedNetworkImage(
placeholder: (context, url) =>
CircularProgressIndicator(),
fit: BoxFit.cover,
//imageUrl: imgUrls![3],
imageUrl: _images[3],
),
),
Padding(
padding: const EdgeInsets.only(
top: 12, left: 23, right: 22, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
'Others',
style: TextStyle(
fontWeight: FontWeight.w700, fontSize: 18),
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
children: [
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Zodiac Sign',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Leo',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
),
SizedBox(width: 20),
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Political inclination',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Apolitics',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
)
],
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: Row(
children: [
Container(
width: 140,
child: Card(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10))),
child: ListTile(
title: Text(
'Movies',
style: TextStyle(
color: Colors.black54, fontSize: 10),
),
subtitle: Text(
'Hindi Cinema',
style: TextStyle(
color: Colors.black87, fontSize: 14),
),
),
),
)
],
),
),
SizedBox(
height: 30,
),
//imgUrls![4] == ''
Container(
height: 569,
child: CachedNetworkImage(
placeholder: (context, url) =>
CircularProgressIndicator(),
fit: BoxFit.cover,
imageUrl: _images[4],
//imageUrl: imgUrls![4],
),
),
SizedBox(
height: 20,
),
//imgUrls![5] == ''
Container(
height: 569,
child: CachedNetworkImage(
placeholder: (context, url) =>
CircularProgressIndicator(),
fit: BoxFit.cover,
imageUrl: _images[5],
//imageUrl: imgUrls![5],
),
),
SizedBox(
height: 80,
)
],
),
),
),
);
},
),
);
}
}
Here, instead of SinglechildScrollView I have also tried to use ListView and ListView.builder but the same problem appears.
You are testing the app in a emulator or a physical device? Debug mode or release?
Using debug mode all the app looks like slow and has a lot of lagging, even more when using a emulator.

Flutter - Align bottom doesn't reach bottom

This is the home page of my app, here I use column to display the page's content: container with Anime of the day and stories scroll container.
By default, everything is OK, but, when I scroll stories (ListView), a crack appears (see attachments), so the gradient doesn't reach the end. What is the problem?
Screenshots:
Before scroll
After scroll
Code snippet:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: 510,
width: double.infinity,
child: Stack(fit: StackFit.expand, children: [
Positioned.fill(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://img5.goodfon.ru/wallpaper/nbig/3/59/shingeki-no-kyojin-ataka-titanov-parni-eren-levi.jpg'),
fit: BoxFit.cover)),
)),
Align(
alignment: Alignment.bottomCenter,
child: Container(
width: double.infinity,
height: 510,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Color(0x15161a),
Color(0x2d15161a),
Color(0xff18191e)
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter)),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Вторжение титанов',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 40,
)),
SizedBox(height: 5),
Text(
'Attack of titans',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 20,
),
),
SizedBox(height: 80),
Row(
children: [
Text(
'приключения',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
SizedBox(
width: 16,
),
Text(
'2021',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
SizedBox(
width: 16,
),
Text(
'18+',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
],
),
SizedBox(
height: 10,
)
]))))
])),
SizedBox(
height: 15,
),
Container(
height: 100,
child: ListView(
physics: BouncingScrollPhysics(),
scrollDirection: Axis.horizontal,
children: [
Row(
children: [
SizedBox(
width: 11,
),
Column(
children: [
CircleAvatar(
radius: 37,
backgroundColor: Color(0xffdddddd),
child: CircleAvatar(
radius: 36,
backgroundColor: Color(0xff1e1f23),
child: CircleAvatar(
radius: 34,
backgroundImage: NetworkImage(
'https://picsum.photos/200/300'),
),
)),
SizedBox(
height: 9,
),
Text(
'Новое',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 11,
),
),
],
),
SizedBox(
width: 9,
),
Column(
children: [
CircleAvatar(
radius: 37,
backgroundColor: Color(0xffdddddd),
child: CircleAvatar(
radius: 36,
backgroundColor: Color(0xff1e1f23),
child: CircleAvatar(
radius: 34,
backgroundImage: NetworkImage(
'https://picsum.photos/200/300'),
),
)),
SizedBox(
height: 9,
),
Text(
'Новое',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 11,
),
),
],
),
SizedBox(
width: 9,
),
Column(
children: [
CircleAvatar(
radius: 37,
backgroundColor: Color(0xffdddddd),
child: CircleAvatar(
radius: 36,
backgroundColor: Color(0xff1e1f23),
child: CircleAvatar(
radius: 34,
backgroundImage: NetworkImage(
'https://picsum.photos/200/300'),
),
)),
SizedBox(
height: 9,
),
Text(
'Новое',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 11,
),
),
],
),
SizedBox(
width: 9,
),
Column(
children: [
CircleAvatar(
radius: 37,
backgroundColor: Color(0xffdddddd),
child: CircleAvatar(
radius: 36,
backgroundColor: Color(0xff1e1f23),
child: CircleAvatar(
radius: 34,
backgroundImage: NetworkImage(
'https://picsum.photos/200/300'),
),
)),
SizedBox(
height: 9,
),
Text(
'Новое',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 11,
),
),
],
),
SizedBox(
width: 9,
),
Column(
children: [
CircleAvatar(
radius: 37,
backgroundColor: Color(0xffdddddd),
child: CircleAvatar(
radius: 36,
backgroundColor: Color(0xff1e1f23),
child: CircleAvatar(
radius: 34,
backgroundImage: NetworkImage(
'https://picsum.photos/200/300'),
),
)),
SizedBox(
height: 9,
),
Text(
'Новое',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 11,
),
),
],
),
SizedBox(
width: 9,
),
Column(
children: [
CircleAvatar(
radius: 37,
backgroundColor: Color(0xffdddddd),
child: CircleAvatar(
radius: 36,
backgroundColor: Color(0xff1e1f23),
child: CircleAvatar(
radius: 34,
backgroundImage: NetworkImage(
'https://picsum.photos/200/300'),
),
)),
SizedBox(
height: 9,
),
Text(
'Новое',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
fontSize: 11,
),
),
],
),
],
)
]),
),
SizedBox(
height: 37,
),
Padding(
padding: EdgeInsets.fromLTRB(11, 0, 0, 11),
child: Column(
children: [
Text(
'Новинки',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w700,
fontSize: 30,
),
),
],
),
),
],
)
Adding margin: EdgeInsets.only(bottom:1) to Container() inside Positioned.fill() solved the problem.
Solution by #ChiragBargoojar

Why TabBar View hides under Tab Bar?

imageWhen I scroll my screen flexible space collapses which is fine but as I scroll my tab bar view a part of It moves under tab bar even if I don't add scroll in Tab Bar view. I am new to flutter, this is my first project. Please help me with this issue. Also I am new to stack overflow. BTW I have to add these lines because stack overflow is giving me this error "It looks like your post is mostly code; please add some more details." :) :)
Heading ##return Scaffold(
appBar: AppBar(title: Text("Author"),),
body: NestedScrollView(
controller: _scrollController,
headerSliverBuilder: (BuildContext context, bool boxIsScrolled){
return <Widget>[
SliverAppBar(
leading: Container(),
backgroundColor: Colors.white,
pinned: true,
floating: true,
forceElevated: boxIsScrolled,
bottom: TabBar(
controller: _tabController,
indicatorSize: TabBarIndicatorSize.tab,
tabs: [
Tab(child: Row(mainAxisAlignment:MainAxisAlignment.center,children:[Icon(Icons.photo_sharp, color: Colors.black,),SizedBox(width: 10.0,),Text("Posts", style: TextStyle(color: Colors.black),)],),),
Tab(child: Row(mainAxisAlignment:MainAxisAlignment.center,children:[Icon(Icons.dashboard_rounded, color: Colors.black,),SizedBox(width: 10.0,),Text("Courses", style: TextStyle(color: Colors.black),)],),),
],
),
flexibleSpace: SafeArea(
child: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: EdgeInsets.all(8),
child: Row(
children: [
CircleAvatar(
radius: 45.0,
child: author.photo_url == null ? Image.asset("assets/user.png") : imageUrl == null ? CircularProgressIndicator():
ClipRRect(
borderRadius: BorderRadius.circular(83.0),
child: Image(
image: NetworkImage(imageUrl),
width: 140,
height: 140,
fit: BoxFit.fill,
),
)),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text("Followers", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 19.0)),
SizedBox(height: 12.0,),
Text("0", style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.0)),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text("Posts", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 19.0)),
SizedBox(height: 12.0,),
Text("0", style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.0)),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text("Courses", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 19.0)),
SizedBox(height: 12.0,),
Text("0", style: TextStyle(fontWeight: FontWeight.w500, fontSize: 18.0)),
],
)
],
),
)
],
),
),
Padding(
padding: EdgeInsets.fromLTRB(18, 8, 0, 0),
child: Text("${author.name}", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, letterSpacing: 1.0),),
),
Padding(
padding: EdgeInsets.fromLTRB(20, 5, 0, 0),
child: Text("${author.qualification}", style: TextStyle(letterSpacing: 1.0),),
),
Padding(
padding: EdgeInsets.fromLTRB(20, 5, 0, 0),
child: Text("${author.profession}", style: TextStyle(letterSpacing: 1.0),),
),
Padding(
padding: EdgeInsets.fromLTRB(20, 15, 20, 0),
child: Container(
width: deviceWidth,
child: RaisedButton.icon(
color: Colors.blue,
label: Text(followedAuthorsID.contains(author.id) ? "Following" : "Follow", style: TextStyle(color: Colors.white, fontWeight: FontWeight.w700, letterSpacing: 0.5),),
icon: Icon(followedAuthorsID.contains(author.id) ? Icons.check_box : Icons.person_add, color: Colors.white,),
onPressed: (){
followAuthor(author, followedAuthorsID.contains(author.id));
},
),
),
),
Divider(height: 40,color: Colors.black,),
]),
),
),
expandedHeight: 305,
)
];
},
body: TabBarView(
controller: _tabController,
children: [
GridView.count(
childAspectRatio: 1,
shrinkWrap: true,
physics: ScrollPhysics(),
crossAxisCount: 3,
children: [
Container(color: Colors.red,),
Container(color: Colors.green,),
Container(color: Colors.red,),
Container(color: Colors.green,),
],
),
// ListView(
// children : [
// SizedBox(height: 100),
// Center(child: Text("No Posts Added", style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22, letterSpacing: 0.5),)),
ListView(
children : [
SizedBox(height: 100,),
Center(child: Text("No Courses Added", style: TextStyle(fontWeight: FontWeight.w500, fontSize: 22, letterSpacing: 0.5),)),
SizedBox(height: 25),
CircleAvatar(
radius: 45,
child: Icon(Icons.dashboard_rounded, size: 35,),
),
]
),
],
),
),
);

how to check if my cloud firestore collection contains contains any documents

I am trying to check if my firestore collection "payments" contains any documents where the string userActive is contained in any document field array called participants,and if it doesn't perform an action or if it does perform a different action, this is what i have tried so far but its not working
import 'package:flutter/material.dart';
import 'package:wallet_app/send.dart';
import 'package:wallet_app/send_money.dart';
import 'package:wallet_app/recieve.dart';
import 'package:wallet_app/load.dart';
import 'package:wallet_app/account.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:wallet_app/CardScreen.dart';
import 'package:flutter_icons/flutter_icons.dart';
class HomeScreener extends StatefulWidget{
HomeScreen createState()=> HomeScreen();
}
class HomeScreen extends State<HomeScreener> {
HomeScreen createState() => HomeScreen();
final databaseReference = FirebaseFirestore.instance;
var userId = "dAIdrQggsrxvQ4KUo2aJ";
var userActive = "kim";
var userHasData = 0;
checkDatabase()async {
final docSnapshot = await FirebaseFirestore.instance
.collection('payments')
.where('participants', arrayContains: userActive)
.getDocuments();
if(docSnapshot.documents.isEmpty) {
// Your queried documents do not exist
userHasData = 1;
}
else if(docSnapshot.documents.isEmpty){
// Your queried documents do not exist
}
userHasData = 2;
}
#override
Widget build(BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height,
width: double.infinity,
child: Stack(
children: <Widget>[
//Container for top data
Container(
margin: EdgeInsets.symmetric(horizontal: 32, vertical: 32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Hello " + "$userActive", style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.w700),),
Container(
margin: EdgeInsets.only(top: 20),
child: Row(
children: <Widget>[
// Icon(Icons.notifications, color: Colors.lightBlue[100],),
SizedBox(width: 16,),
CircleAvatar(
radius: 25,
backgroundColor: Colors.white,
child: ClipOval(
child: Image.asset("assets/newdp.png", fit: BoxFit.contain,),
),
)
],
),
)
],
),
Text("What would you like to do today?", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 16, color: Colors.blue[100]),),
SizedBox(height : 40,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(243, 245, 248, 1),
borderRadius: BorderRadius.all(Radius.circular(18))
),
child:IconButton(
icon: Icon(Icons.send, color: Colors.blue[900], size: 30,),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => sendPager()),
);
},
),
padding: EdgeInsets.all(3),
),
SizedBox(
height: 10,
),
Text("Send", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 14, color: Colors.blue[100]),),
],
),
),
Container(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(243, 245, 248, 1),
borderRadius: BorderRadius.all(Radius.circular(18))
),
child:IconButton(
icon: Icon(Icons.account_balance, color: Colors.blue[900], size: 30,),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => loadPager()),
);
},
),
padding: EdgeInsets.all(3),
),
SizedBox(
height: 10,
),
Text("Account", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 14, color: Colors.blue[100]),),
],
),
),
Container(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(243, 245, 248, 1),
borderRadius: BorderRadius.all(Radius.circular(18))
),
child:IconButton(
icon: Icon(Icons.people, color: Colors.blue[900], size: 30,),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => loadPager()),
);
},
),
padding: EdgeInsets.all(3),
),
SizedBox(
height: 10,
),
Text("Recipients", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 14, color: Colors.blue[100]),),
],
),
),
Container(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Color.fromRGBO(243, 245, 248, 1),
borderRadius: BorderRadius.all(Radius.circular(18))
),
child:IconButton(
icon: Icon(Icons.add, color: Colors.blue[900], size: 30,),
onPressed: () {
databaseReference.collection("payments").add(
{
"amount_paid" : "2444242",
"amount_received" : "33535",
"currency_received" : "¥",
"currency_sent" :"K",
'date':FieldValue.serverTimestamp(),
"participants" :["kim", "john" ],
"receiver_name" : "john",
"sender_name" : "kim"
}).then((value){
print("================================sucess=============================================================");
print(value.documentID);
});
Navigator.push(
context,
MaterialPageRoute(builder: (context) => loadPager()),
);
},
),
padding: EdgeInsets.all(3),
),
SizedBox(
height: 10,
),
Text("Invite", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 14, color: Colors.blue[100]),),
],
),
)
],
)
],
),
),
//draggable sheet
DraggableScrollableSheet(
builder: (context, scrollController){
return Container(
decoration: BoxDecoration(
color: Color.fromRGBO(243, 245, 248, 1),
borderRadius: BorderRadius.only(topLeft: Radius.circular(40), topRight: Radius.circular(40))
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 24,),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("Recent Transactions", style: TextStyle(fontWeight: FontWeight.w900, fontSize: 24, color: Colors.black),),
Text("See all", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 16, color: Colors.grey[800]),)
],
),
padding: EdgeInsets.symmetric(horizontal: 32),
),
SizedBox(height: 24,),
//Container for buttons
Container(
padding: EdgeInsets.symmetric(horizontal: 32),
child: Row(
children: <Widget>[
Container(
child: Text("All", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 14, color: Colors.grey[900]),),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20)),
boxShadow: [BoxShadow(color: Colors.grey[200], blurRadius: 10.0, spreadRadius: 4.5)]
),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
),
SizedBox(width: 16,),
Container(
child: Row(
children: <Widget>[
CircleAvatar(
radius: 8,
backgroundColor: Colors.green,
),
SizedBox(
width: 8,
),
Text("Recieved", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 14, color: Colors.grey[900]),),
],
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20)),
boxShadow: [BoxShadow(color: Colors.grey[200], blurRadius: 10.0, spreadRadius: 4.5)]
),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
),
SizedBox(width: 16,),
Container(
child: Row(
children: <Widget>[
CircleAvatar(
radius: 8,
backgroundColor: Colors.orange,
),
SizedBox(
width: 8,
),
Text("Transfer", style: TextStyle(fontWeight: FontWeight.w700, fontSize: 14, color: Colors.grey[900]),),
],
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20)),
boxShadow: [BoxShadow(color: Colors.grey[200], blurRadius: 10.0, spreadRadius: 4.5)]
),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
)
],
),
),
SizedBox(height: 16,),
//Container Listview for expenses and incomes
Container(
child: Text(" ", style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Colors.grey[500]),),
padding: EdgeInsets.symmetric(horizontal: 32),
),
SizedBox(height: 5),
StreamBuilder(
stream: FirebaseFirestore.instance.collection("payments").where('participants', arrayContains: userActive).snapshots(),
builder: (context, snapshot){
checkDatabase();
return Container ( child:ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.documents.length,
padding: EdgeInsets.all(0),
controller: ScrollController(keepScrollOffset: false),
itemBuilder: (context, index){
DocumentSnapshot documentSnapshot = snapshot.data.docs[index];
//if(snapshot.connectionState == ConnectionState.active && snapshot.hasData) {
if(userHasData == 1){
print(" no Data!!!");
return Center(child: Text("No Data"));
}
else if (userHasData == 2){
print("Found Data!!!");
if(documentSnapshot.data()["receiver_name"] == userActive ) {
return Container(
margin: EdgeInsets.symmetric(horizontal: 32,vertical: 5),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Row(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.all(Radius.circular(18))
),
child: Icon(Icons.attach_money, color: Colors.lightBlue[900],),
padding: EdgeInsets.all(12),
),
SizedBox(width: 16,),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Recieved", style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: Colors.grey[900]),) ,
Text("" + documentSnapshot.data()["currency_received"] + documentSnapshot.data()["amount_received"], style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Colors.grey[500]),),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text("+ " + documentSnapshot.data()["currency_sent"] + documentSnapshot.data()["amount_paid"].toString(), style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: Colors.lightGreen),),
Text(documentSnapshot.data()["date"].toDate().toString(), style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Colors.grey[500]),),
],
),
],
),
);
}else if (documentSnapshot.data()["sender_name"] == userActive){
return Container(
margin: EdgeInsets.symmetric(horizontal: 32,vertical: 5),
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Row(
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.all(Radius.circular(18))
),
child: Icon(Icons.attach_money, color: Colors.lightBlue[900],),
padding: EdgeInsets.all(12),
),
SizedBox(width: 16,),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Sent", style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: Colors.grey[900]),) ,
Text("" + documentSnapshot.data()["currency_received"] + documentSnapshot.data()["amount_received"], style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Colors.grey[500]),),
],
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text("- " + documentSnapshot.data()["currency_sent"] + documentSnapshot.data()["amount_paid"].toString(), style: TextStyle(fontSize: 18, fontWeight: FontWeight.w700, color: Colors.orange),),
Text(documentSnapshot.data()["date"].toDate().toString(), style: TextStyle(fontSize: 15, fontWeight: FontWeight.w700, color: Colors.grey[500]),),
],
),
],
),
);
}
}
// } return Center(child: const CircularProgressIndicator());
}
)
);
}
),
],
),
controller: scrollController,
),
);
},
initialChildSize: 0.65,
minChildSize: 0.65,
maxChildSize: 1,
)
],
),
);
}
}
Try using .exists :
final docSnapshot = await Firestore.instance.collection('payments').document("document_id").get();
if (docSnapshot.exists){
//document exists
}
else{
//document does not exists
}
for all documents:
final doc = await Firestore.instance.collection('payments').getDocuments();
if (doc.documents.isEmpty){
//Collection is empty
}
else{
//collection has documents
}
You can apply the logic before using it in the element, like on start of the class then use futureBuilder. You can set a bool using the above logic and then using the visibility widget to show the futureBuilder only if the document is available.
For your case:
final docSnapshot = await Firestore.instance
.collection('bus_information_user')
.where('participants', arrayContains: userActive)
.getDocuments();
if(docSnapshot.documents.isEmpty){
// Your queried dosuments does not exist
}
else{
// Your queried dosuments does exist
}
Ps:. I have not tried out the last part but should do the job.

Categories

Resources