How to add Icon on GridView Selected Item - flutter

Hey i am new in flutter please help me in my problem.My issue is that when i select a gridview item using inkWell() then image and text both no changed. I dont know why setState() method not work.
Widget getAdaptor( var index) {
bool isSelected = false;
return InkWell(
onTap: () {
setState(() {
isSelected = !isSelected;
print('' + isSelected.toString());
});
},
child: Container(
child: Column(
children: <Widget>[
Container(height: 80, width: 80, child: Image.network(imageBaseUrl)),
Row(
children: <Widget>[
Expanded(
child: Text(
'$title',
style: TextStyle(
color: isSelected ? Colors.red : Colors.black),
),
),
Container(
child: isSelected == true
? Image.asset(
'images/bike.png',
height: 20,
width: 20,
)
: Image.asset(
'images/tick.png',
width: 20,
height: 20,
),
)
],
),
],
)),
); }

You just remind me of how I was doing when I was new to this language.
Remember if you want to use setState(() {}); you need to put that variable outside a build widget
So, you can just put bool isSelected = false; outside a method and everything will be just fine.
Like this:
bool isSelected = false;
Widget getAdaptor(var index) {
return InkWell(
onTap: () {
setState(() {
isSelected = !isSelected;
print('' + isSelected.toString());
});
},
child: Container(
child: Column(
children: <Widget>[
Container(height: 80, width: 80, child: Image.network(imageBaseUrl)),
Row(
children: <Widget>[
Expanded(
child: Text(
'$title',
style:
TextStyle(color: isSelected ? Colors.red : Colors.black),
),
),
Container(
child: isSelected == true
? Image.asset(
'images/bike.png',
height: 20,
width: 20,
)
: Image.asset(
'images/tick.png',
width: 20,
height: 20,
),
)
],
),
],
)),
);
}

Your widget needs to be a stateful widget, as you are keeping track of isSelected and are updating the UI. With the current setup, the entire widget is rebuilt every time the state is changed, which also resets isSelected to false.
This should do what you want:
class Adapter extends StatefulWidget{
#override
State<StatefulWidget> createState() {
return _AdapterState();
}
}
class _AdapterState extends State<Adapter>{
bool isSelected = false;
#override
Widget build(BuildContext context) {
return InkWell(
onTap: () {
setState(() {
isSelected = !isSelected;
print('' + isSelected.toString());
});
},
child: Container(
child: Column(
children: <Widget>[
Container(height: 80, width: 80, decoration: BoxDecoration(color: Colors.red)),
Row(
children: <Widget>[
Expanded(
child: Text(
'test',
style: TextStyle(
color: isSelected ? Colors.red : Colors.black),
),
),
Container(
child: isSelected == true
? Image.asset(
'images/bike.png',
height: 20,
width: 20,
)
: Image.asset(
'images/tick.png',
width: 20,
height: 20,
),
)
],
),
],
)),
);
}

Related

Flutter: pass data from one screen to another based on a list that I fetch from API

I am building a Job Find app on flutter and I am facing some State Management problems. I have a screen where I show all of my job listings (job_list_screen.dart) and if the user press on a job the app loads this specific job with all the details(job_details_screen.dart).
enter image description here
enter image description here
As you can see, I have an apply button(the blue button) on both screens. When I press apply on the job_details_screen I send a put request on my database and it works fine. But, when I go back to my job_list_screen the button doesn't change even thought I wrapped it with a Consumer.
enter image description here
enter image description here
Here is all the code I wrote with the providers, the **screens **and the **widgets **I use.
The jobs provider:
First of all, this is how I fetch jobs from the API and I insert all my data in a List model:
`
/*
|--------------------------------------------------------------------------
| Fetch Jobs from database
|--------------------------------------------------------------------------
|
| 1. set the url for this function
| 2. GET the response from the server only if you are authenticated
| 3. Decode the
response.body: {
'listings': {
'data': (*Inside here, there are all the job list*)
}
}
| 4. For every job inside the data response
| add a new Job item in the List<Job>
| with the named variables from the current data.reposnse.job
*/
Future<List<Job>?> fetchJobs() async {
final key = await storage.read(key: 'auth');
final baseUrl = AppUrl.baseUrl;
try {
// 1.
var url = Uri.parse('$baseUrl/listings');
// 2.
var response = await http.get(
url,
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $key',
},
);
// print(key);
if (response.statusCode == 200 || response.statusCode == 201) {
// 3.
var jsonResponse = jsonDecode(response.body)['listings']['data'];
_jobs = [];
// 4.
for (var j in jsonResponse) {
Job job = Job(
id: j['id'],
title: j['title'],
employmentType: j['employmentType'],
major: j['major'],
city: j['city'],
companyName: j['companyName'],
experience: j['experience'],
date: j['date'],
views: j['views'],
description: j['description'],
benefits: j['benefits'],
requirements: j['requirements'],
hasApplied: j['hasApplied'],
hasViewed: j['hasViewed'],
);
_jobs.add(job);
notifyListeners();
}
notifyListeners();
return _jobs;
} else {
throw Exception('Problem loading jobs');
}
} catch (e) {
print(e);
}
}
`
This is the function that I call when the user presses the apply button:
`
/*
|--------------------------------------------------------------------------
| Apply for a job
|--------------------------------------------------------------------------
*/
Future<void> applyJob(String id) async {
final key = await storage.read(key: 'auth');
final baseUrl = AppUrl.baseUrl;
try {
var url = Uri.parse('$baseUrl/listings/$id/apply');
var response = await http.put(
url,
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $key',
},
);
if (response.statusCode == 200 || response.statusCode == 201) {
print(jsonDecode(response.body));
_hasApplied = jsonDecode(response.body)['hasApplied'];
notifyListeners();
} else {
print(jsonDecode(response.body));
notifyListeners();
}
} catch (e) {
print(e);
}
notifyListeners();
}
`
The job_card widget:
`
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:final_try/screens/job_details_screen.dart';
import '../models/job.dart';
import '../providers/jobs.dart';
import '../styles/colors.dart';
class JobCardBig extends StatefulWidget {
static const routeName = '/job-card-big';
#override
State<JobCardBig> createState() => _JobCardBigState();
}
class _JobCardBigState extends State<JobCardBig> {
#override
Widget build(BuildContext context) {
final job = Provider.of<Job>(context, listen: true);
return Container(
padding: EdgeInsets.all(10),
margin: EdgeInsets.only(bottom: 10),
width: double.infinity,
decoration: BoxDecoration(
border: Border.all(color: lightgrey, width: 1),
borderRadius: BorderRadius.circular(5.0),
boxShadow: [
BoxShadow(
color: lightgrey.withOpacity(.5),
spreadRadius: 1,
blurRadius: 2,
offset: Offset(0, 1), // changes position of shadow
),
],
color: white,
),
child: Column(children: [
Container(
child: Row(
children: [
Container(
height: 50,
width: 50,
alignment: Alignment.center,
decoration:
BoxDecoration(shape: BoxShape.circle, color: lightgrey),
),
SizedBox(
width: 10,
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
height: 70,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
job.title.toString(),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Text(
job.companyName.toString(),
style: TextStyle(
fontSize: 14,
color: lightgrey,
),
),
],
),
),
),
Container(
height: 70,
width: 50,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Icon(
Icons.remove_red_eye,
size: 14,
color: darkgrey,
),
SizedBox(
width: 5,
),
Text(
job.views == null
? job.views = '0'
: job.views.toString(),
style: TextStyle(
fontSize: 14,
color: darkgrey,
),
),
],
),
],
),
),
],
),
),
],
)),
SizedBox(
height: 5,
),
Divider(
thickness: 1,
),
SizedBox(
height: 5,
),
Container(
height: 80,
alignment: Alignment.bottomLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
'Είδος Απασχόλησης:',
),
SizedBox(
width: 5,
),
Text(
Provider.of<Jobs>(context, listen: false)
.jobTypeFormat(job.employmentType.toString()),
style: TextStyle(color: lightgrey),
),
],
),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Προϋπηρεσία:'),
SizedBox(
width: 5,
),
Flexible(
child: job.experience == null
? Text(
'Δεν απαιτείται',
style: TextStyle(color: lightgrey),
)
: job.experience! > 1
? Text(
'${job.experience.toString()} χρόνια',
style: TextStyle(color: lightgrey),
)
: Text(
'${job.experience.toString()} χρόνο',
style: TextStyle(color: lightgrey),
),
),
],
),
Row(
children: [
Text('Τοποθεσία:'),
SizedBox(
width: 5,
),
Text(
job.city.toString(),
style: TextStyle(color: lightgrey),
),
],
),
Row(
children: [
Text('Δημοσιεύθηκε:'),
SizedBox(
width: 5,
),
Text(
Provider.of<Jobs>(context, listen: false)
.dateFormat(job.date),
// job.date.toString(),
style: TextStyle(color: lightgrey),
),
],
),
],
),
),
Container(
margin: EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
border: Border.all(color: darkgrey, width: 1),
borderRadius: BorderRadius.circular(5.0),
color: darkgrey,
),
child: Text(
'Περισσότερα',
style: TextStyle(color: white),
),
),
onTap: () {
Navigator.of(context)
.pushNamed(JobDetailsScreen.routeName, arguments: job.id)
.then((_) {
// Provider.of<Jobs>(context, listen: false).fetchJobs();
});
},
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: job.hasApplied == 1
? Color.fromARGB(255, 196, 76, 68)
: buttonColor,
),
child: Consumer<Job>(
builder: (context, job, child) {
return Text(
job.hasApplied == 1 ? 'Δεν ενδιαφέρομαι' : 'Αίτηση',
style: TextStyle(
color: white,
),
);
},
),
),
],
),
),
]),
);
}
}
`
The job_list_screen:
Here I load all my job_card widgets with ListView.builder
`
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
import '../styles/colors.dart';
import '../providers/jobs.dart';
import '../widgets/header_screen.dart';
import '../widgets/job_card_big.dart';
class JobListScreen extends StatefulWidget {
static const routeName = '/job-list-screen';
const JobListScreen({super.key});
#override
State<JobListScreen> createState() => _JobListScreenState();
}
class _JobListScreenState extends State<JobListScreen> {
final controller = ScrollController();
bool _firstLoading = true;
var _isLoading = false;
int page = 1;
final _formKey = GlobalKey<FormState>();
String? _searchText;
bool _isFiltered = false;
#override
void initState() {
controller.addListener(() {
if (controller.position.maxScrollExtent == controller.offset) {
fetch();
}
});
super.initState();
}
Future fetch() async {
if (!_isFiltered) {
setState(() {
_isLoading = true;
page++;
Provider.of<Jobs>(context, listen: false)
.fetchMore(page)
.then((_) => _isLoading = false);
});
}
}
#override
void didChangeDependencies() {
if (_firstLoading) {
Provider.of<Jobs>(context, listen: true).fetchJobs().then((_) {
setState(() {
_firstLoading = false;
});
});
}
super.didChangeDependencies();
}
void searchJob() {
if(_searchText == null || _searchText == ''){
setState(() {
_isFiltered = false;
});
}
else setState(() {
Provider.of<Jobs>(context, listen: false).filterJobs(_searchText!);
_isFiltered = true;
});
}
#override
Widget build(BuildContext context) {
final jobsData = Provider.of<Jobs>(context, listen: true);
var jobsList = jobsData.jobs;
var filteredList = jobsData.filteredJobs;
// var jobsListFiltered = jobsData.filteredJobs;
return Scaffold(
body: Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
padding: EdgeInsets.only(
top: 20,
right: 20,
left: 20,
),
child: Column(
children: [
HeaderScreen(title: 'Αγγελίες'),
Container(
child: Form(
key: _formKey,
child: Row(
children: [
Expanded(
child: Container(
child: TextFormField(
decoration: InputDecoration(
hintText: 'Enter some text',
),
onSaved: (value) {
_searchText = value;
},
),
),
),
Container(
margin: EdgeInsets.only(top: 10, bottom: 5),
height: 40,
width: 40,
child: ElevatedButton(
style: ButtonStyle(
foregroundColor:
MaterialStateProperty.all<Color>(white),
backgroundColor: MaterialStateProperty.all<Color>(
primaryColor),
),
child: Container(
child: Icon(Icons.search),
),
onPressed: () {
_formKey.currentState?.save();
searchJob();
},
),
),
],
),
),
),
SizedBox(
height: 10,
),
Divider(
thickness: 1,
),
SizedBox(
height: 10,
),
Expanded(
child: !_isFiltered
? Container(
child: !_firstLoading
? ListView.builder(
controller: controller,
itemCount: jobsList.length,
itemBuilder: (ctx, i) =>
ChangeNotifierProvider.value(
value: jobsList[i],
child: Column(
children: [
JobCardBig(),
],
),
),
)
: Center(
child: CircularProgressIndicator(),
),
)
: Container(
child: !_firstLoading
? ListView.builder(
controller: controller,
itemCount: filteredList.length,
itemBuilder: (ctx, i) =>
ChangeNotifierProvider.value(
value: filteredList[i],
child: Column(
children: [
JobCardBig(),
],
),
),
)
: Center(
child: CircularProgressIndicator(),
),
),
),
],
),
),
Positioned(
child: _isLoading
? Container(
width: double.infinity,
height: MediaQuery.of(context).size.height,
color: Color.fromARGB(52, 0, 0, 0),
child: Center(
child: CircularProgressIndicator(),
),
)
: Container(),
),
],
),
);
}
}
`
I tried to load my fetchJobs() function when the user exits the job_details_screen but even though it works, it is not the right solution. The reason why I say that this is not the right way, is because of this possible scenario:
If the user scrolls down a lot, and the app load 60 jobs, then if he presses on job 60, and he exit the job_details_screen, the app will load the first 15 jobs and the user will have to scroll down again. And that's not the user experience I want to provide.
I am searching for a solution that will update only the apply button and it will not need to recreate the whole list. Plus, with this solution the user will go back to the same scroll point he was when he entered the job_details_screen.
I hope I explained my problem properly. This is the first time I upload a question here and I would also like to mention that this is my first project on flutter so don't judge my code too harshly.
Thanks in advance!!

how to get a button to update a counter only once when pressed the first time?

I have two container buttons (blue and red) that alternate being visible when pressed. plus a counter that ticks up each time the blue button is pressed.
class Test extends StatefulWidget {
const Test({Key? key}) : super(key: key);
#override
State<Test> createState() => _TestState();
}
class _TestState extends State<Test> {
int counter = 0;
bool blueVisibility = true;
bool redVisibility = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: Container(
child: Visibility(
visible: blueVisibility,
child: InkWell(
onTap: () {
setState(() {
redVisibility = true;
blueVisibility = false;
counter++;
});
},
child: Container(
margin: EdgeInsets.all(10),
color: Colors.blue,
height: 80,
width: 50,
),
),
),
),
),
Expanded(
child: Container(
child: Visibility(
visible: redVisibility,
child: InkWell(
onTap: () {
setState(() {
redVisibility = false;
blueVisibility = true;
});
},
child: Container(
margin: EdgeInsets.all(10),
color: Colors.red,
height: 80,
width: 50,
),
),
),
),
),
],
),
),
Container(
height: 50,
width: 50,
color: Colors.blueGrey,
alignment: Alignment.center,
child: Text(
'$counter',
style: TextStyle(
fontSize: 40,
),
),
),
],
),
);
}
}
Is it possible to make it so the blue box only adds to the counter the first time it is pressed and then not again after that while still retaining the ability to press the boxes to make them visible/invisible?
thanks so much
you can just wrap the code with an if else statement to achieve what you want like the following.
in the onTap of the blue container button:
onTap: () {
setState(() {
redVisibility = true;
blueVisibility = false;
if(counter < 1) {
counter++;
}
});
},
this will let the counter increment just one time.
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
int counter = 0;
bool blueVisibility = true;
bool redVisibility = false;
int check=0;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Expanded(
child: Row(
children: [
Expanded(
child: Container(
child: Visibility(
visible: blueVisibility,
child: InkWell(
onTap: () {
setState(() {
redVisibility = true;
blueVisibility = false;
if(check==0){
counter++;
check++;}
});
},
child: Container(
margin: EdgeInsets.all(10),
color: Colors.blue,
height: 80,
width: 50,
),
),
),
),
),
Expanded(
child: Container(
child: Visibility(
visible: redVisibility,
child: InkWell(
onTap: () {
setState(() {
redVisibility = false;
blueVisibility = true;
});
},
child: Container(
margin: EdgeInsets.all(10),
color: Colors.red,
height: 80,
width: 50,
),
),
),
),
),
],
),
),
Container(
height: 50,
width: 50,
color: Colors.blueGrey,
alignment: Alignment.center,
child: Text(
'$counter',
style: TextStyle(
fontSize: 40,
),
),
),
],
),
);}
}

How to Insert The Color Picker Without Using Show Dialog In Flutter

i just want to insert the color picker without using show dialog and setState because im using bloc provider. and i dont know how to call a color picker
Container(
width: 300,
margin: const EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text (
'LED Color',
style:TextStyle(
fontSize: 25,
),
),
SingleChildScrollView(
child: ColorPicker(
pickerColor : pickerColor,
onColorChange: changeColor,
),
)
// SingleChildScrollView(
// child: ColorPicker(
// pickerColor: pickerColor,
// onColorChange: changeColor
// )),
],
),
),
ColorPicker is a widget place on any place. It is not mandatory to place on dialog.
class ASDXf extends StatefulWidget {
const ASDXf({Key? key}) : super(key: key);
#override
State<ASDXf> createState() => _ASDXfState();
}
class _ASDXfState extends State<ASDXf> {
Color selectedColor = Colors.purple;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: 300,
margin: const EdgeInsets.fromLTRB(0, 20, 0, 0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
height: 100,
width: 100,
color: selectedColor,
),
const Text(
'LED Color',
style: TextStyle(
fontSize: 25,
),
),
SingleChildScrollView(
child: ColorPicker(
pickerColor: selectedColor,
onColorChanged: (value) {
selectedColor = value;
setState(() {});
},
),
),
],
),
),
);
}
}

add dynamic widgets on tap and save values flutter

I'm trying to add a new row of widgets (select gender and age from a drop-down menu ) when a user taps on adding a child and saves different data from each row also when deleting a child by index it should not affect the other values the user entered how can I achieve that?
this is the UI
UI
and here's the code
class ChildrenSection extends StatefulWidget {
const ChildrenSection({
Key? key,
}) : super(key: key);
#override
State<ChildrenSection> createState() => _ChildrenSectionState();
}
class _ChildrenSectionState extends State<ChildrenSection> {
int _count = 1;
List<String>? onGenderSelected;
#override
Widget build(BuildContext context) {
onGenderSelected = List<String>.filled(_count, '', growable: true);
return Row(
children: [
Text(
'Children',
style: NannyFinderTheme.createAdTextStyle,
),
SizedBox(
width: 10.w,
),
Expanded(
child: Column(
children: [
SizedBox(
height: (50 * _count).toDouble(),
child: ListView.builder(
itemCount: onGenderSelected?.length,
itemBuilder: (context, index) {
return _addChild(index);
}),
),
SizedBox(
height: 10.h,
),
InkWell(
onTap: () {
setState(() {
_count++;
});
},
child: Row(
children: [
const Icon(CupertinoIcons.person_badge_plus_fill),
SizedBox(
width: 10.w,
),
const Text(
'Add a child',
style: TextStyle(decoration: TextDecoration.underline),
)
],
),
)
],
),
),
],
);
}
Widget _addChild(int index) {
return Row(
children: [
InkWell(
onTap: () {
if (index != 0) {
setState(() {
_count--;
});
}
},
child: Icon(index == 0
? CupertinoIcons.person_fill
: CupertinoIcons.person_badge_minus_fill)),
SizedBox(
width: 10.w,
),
_children('Girl', index),
SizedBox(
width: 4.w,
),
_children('Boy', index),
//const Spacer(),
SizedBox(
width: 10.w,
),
Expanded(
child: CustomDropDownButton(
value: kListOfChildrenAge.first,
menuList: kListOfChildrenAge,
onChanged: (String? value) {},
),
)
],
);
}
Widget _children(String text, int index) {
return InkWell(
onTap: () {
setState(() {
onGenderSelected?[index] = text;
});
},
child: Container(
height: 30,
padding: EdgeInsets.symmetric(horizontal: 8.w),
decoration: BoxDecoration(
color: onGenderSelected?[index] == text
? NannyFinderTheme.ligtherPrimaryColor
: Colors.white,
borderRadius: BorderRadius.circular(4.r),
border: Border.all(width: 0.5, color: NannyFinderTheme.grayColor)),
child: Center(
child: Text(
text,
style: TextStyle(
color: onGenderSelected?[index] == text
? Colors.white
: Colors.black,
fontWeight: FontWeight.bold),
)),
),
);
}
}

setState() or markNeedsBuild() called during build. when call native ad

import 'package:facebook_audience_network/ad/ad_native.dart';
import 'package:facebook_audience_network/facebook_audience_network.dart';
import 'package:flutter/material.dart';
import 'package:share/share.dart';
import 'package:social_share/social_share.dart';
import 'package:clipboard_manager/clipboard_manager.dart';
// ignore: camel_case_types
class listview extends StatefulWidget {
const listview({
Key key,
#required this.records,
}) : super(key: key);
final List records;
#override
_listviewState createState() => _listviewState();
}
// ignore: camel_case_types
class _listviewState extends State<listview> {
#override
void initState() {
super.initState();
FacebookAudienceNetwork.init(
testingId: "35e92a63-8102-46a4-b0f5-4fd269e6a13c",
);
// _loadInterstitialAd();
// _loadRewardedVideoAd();
}
// ignore: unused_field
Widget _currentAd = SizedBox(
width: 0.0,
height: 0.0,
);
Widget createNativeAd() {
_showNativeAd() {
_currentAd = FacebookNativeAd(
adType: NativeAdType.NATIVE_AD,
backgroundColor: Colors.blue,
buttonBorderColor: Colors.white,
buttonColor: Colors.deepPurple,
buttonTitleColor: Colors.white,
descriptionColor: Colors.white,
width: double.infinity,
height: 300,
titleColor: Colors.white,
listener: (result, value) {
print("Native Ad: $result --> $value");
},
);
}
return Container(
width: double.infinity,
height: 300,
child: _showNativeAd(),
);
}
#override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: this.widget.records.length,
itemBuilder: (BuildContext context, int index) {
var card = Container(
child: Card(
margin: EdgeInsets.only(bottom: 10),
elevation: 10,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(1.0),
),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () {
print(this.widget.records);
},
child: Image.asset(
"assets/icons/avatar.png",
height: 45,
),
),
),
Padding(
padding: const EdgeInsets.only(left: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
(this
.widget
.records[index]['fields']['Publisher Name']
.toString()),
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
(this
.widget
.records[index]['fields']['Date']
.toString()),
style: TextStyle(
fontSize: 12,
),
),
],
),
)
],
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: MediaQuery.of(context).size.width * 0.90,
// height: MediaQuery.of(context).size.height * 0.20,
decoration: BoxDecoration(
border: Border.all(
color: Colors.purple,
width: 3.0,
),
),
child: Center(
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Text(
(this
.widget
.records[index]['fields']['Shayari']
.toString()),
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
GestureDetector(
onTap: () {
ClipboardManager.copyToClipBoard(this
.widget
.records[index]['fields']['Shayari']
.toString())
.then((result) {
final snackBar = SnackBar(
content: Text('Copied to Clipboard'),
);
Scaffold.of(context).showSnackBar(snackBar);
});
print(this
.widget
.records[index]['fields']['Shayari']
.toString());
},
child: Image.asset(
"assets/icons/copy.png",
height: 25,
),
),
GestureDetector(
onTap: () async {
SocialShare.checkInstalledAppsForShare().then(
(data) {
print(data.toString());
},
);
},
child: Image.asset(
"assets/icons/whatsapp.png",
height: 35,
),
),
GestureDetector(
onTap: () async {
Share.share("Please Share https://google.com");
},
child: Image.asset(
"assets/icons/share.png",
height: 25,
),
),
],
),
SizedBox(
height: 5,
),
],
),
),
);
return Column(
children: [
card,
index != 0 && index % 5 == 0
? /* Its Show When Value True*/ createNativeAd()
: /* Its Show When Value false*/ Container()
],
);
},
);
}
}
I Am Having This Error setState() or markNeedsBuild() called during build.
I Try To Call Facebook Native Ads Between My Dynamic List View But Showing this error when I call native ad createNativeAd This is My Widget Where I set Native ad
This is code where I call ad
** return Column(
children: [
card,
index != 0 && index % 5 == 0
? /* Its Show When Value True*/ createNativeAd()
: /* Its Show When Value false*/ Container()
],
);
},
);**