swipe_cards
swipe_cards copied to clipboard
The getter 'width' was called on null.
This L287 throwing an error of The getter 'width' was called on null.
Is there a way to fix this?
List<SwipeItem> _swipeItems = [];
final MatchEngine matchEngine = new MatchEngine(
swipeItems: edges.map((edge) {
final post = Post.fromJson(edge);
final swipeItem = SwipeItem(
content: post,
likeAction: () {
launchURL(post.node.slug);
},
);
_swipeItems.add(swipeItem);
return swipeItem;
}).toList());
return MyHomePage(
matchEngine: matchEngine,
swipeItems: _swipeItems,
);
Using it as follows.
Then in MyHomePage
Scaffold(
appBar: _buildAppBar(),
body: Center(
child: Container(
constraints: BoxConstraints(
minWidth: 300,
maxWidth: 500,
maxHeight: 730,
),
padding: EdgeInsets.all(10),
child: SwipeCards(
matchEngine: matchEngine,
itemBuilder: (BuildContext context, int index) {
return ProfileCard(
post: swipeItems[index].content,
);
},
onStackFinished: () {
print('finished');
},
),
),
),
bottomNavigationBar: _buildBottomBar(),
);
I have the same issue
Same here
I have the same issue too. Does anyone find a way to fix this?
Same issue
@subhendukundu Is the app crashing due to this exception? I can see this in the logs but don't see any effect on the app. Though to avoid this exception, I've used null aware access
on anchorBounds width and height.
anchorBounds?.width
anchorBounds?.height
@AnupKumarPanwar I've stored some data on a localhost monogdb database and am getting the data from there to render it on my explorer page. While running the app, it sometimes gives an error of "NoSuchMethodError: : Getter Length called on null", not always.
Initially I thought importing the non-null safe version would solve the issue but it still persists. I have enclosed my code below, please tell me how to solve it.
Here, userExplorer is of the type List where Explorer is a custom class where the data from snapshot is stored.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:swipe_cards/swipe_cards.dart';
import 'package:tinder_clone/models/explorer.dart';
import 'package:tinder_clone/provider/explorer_profile.dart';
class ExplorerPage extends StatefulWidget {
final String email;
ExplorerPage({required this.email});
@override
_ExplorerPageState createState() => _ExplorerPageState();
}
class _ExplorerPageState extends State<ExplorerPage> {
MatchEngine _matchEngine = MatchEngine();
List<SwipeItem> _swipeItems = [];
getLength() async {
var userExplorer =
await ExploreProfileProvider().getExplorerProfile(widget.email);
// for (int i = 0; i < userExplorer.length; i++) {
// _swipeItems.add(
// SwipeItem(
// likeAction: () {},
// nopeAction: () {},
// ),
// );
// }
for (var i in userExplorer) {
_swipeItems.add(SwipeItem(
likeAction: () {
print('Right Swipe ${i.name}');
},
nopeAction: () {
print('Left Swipe ${i.name}');
},
));
}
_matchEngine = MatchEngine(swipeItems: _swipeItems);
}
@override
void initState() {
super.initState();
getLength();
}
@override
Widget build(BuildContext context) {
final availableHeight = MediaQuery.of(context).size.height -
AppBar().preferredSize.height -
MediaQuery.of(context).padding.top -
MediaQuery.of(context).padding.bottom;
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: FutureBuilder<List<Explorer>>(
future: ExploreProfileProvider().getExplorerProfile(widget.email),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: [
SwipeCards(
matchEngine: _matchEngine,
itemBuilder: (BuildContext context, int index) {
return Stack(
alignment: Alignment.bottomLeft,
children: [
Container(
width: MediaQuery.of(context).size.width,
height: availableHeight * 0.85,
child: snapshot.data![index].image != ""
? Image.memory(
base64Decode(
snapshot.data![index].image),
fit: BoxFit.cover)
: Image.asset(
'assets/images/img_1.jpeg',
fit: BoxFit.cover,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text(
'${snapshot.data![index].name} 25',
style: GoogleFonts.robotoSlab(
fontWeight: FontWeight.bold,
fontSize: 20.0,
color: Colors.white,
),
),
),
Container(
margin: EdgeInsets.only(bottom: 10),
child: Row(
children: [
Icon(Icons.location_on_outlined),
Container(
margin: EdgeInsets.only(left: 10),
child:
Text(snapshot.data![index].city),
),
],
),
),
],
),
],
);
},
onStackFinished: () {
// print(_swipeItems);
print('Finished');
},
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
icon: Image.asset(
'assets/icons/close_icon.png',
scale: 0.7,
),
padding: EdgeInsets.all(0),
// iconSize: 45,
onPressed: () {
_matchEngine.currentItem.nope();
},
),
IconButton(
icon: Image.asset(
'assets/icons/like_icon.png',
scale: 0.7,
),
// iconSize: 45,
onPressed: () {
_matchEngine.currentItem.like();
},
),
],
),
],
);
} else if (snapshot.hasError) {
print(snapshot.error);
return Text('null');
} else {
return Center(
child: CircularProgressIndicator(
color: Colors.white,
),
);
}
}),
),
),
);
}
}
// class Content {
// final String text;
// final Color color;
// Content({required this.text, required this.color});
// }