I requested image from api, some times users haven't employee images. How to set bydefault image If request image null?
try {
return Image.network(
"$_url/nativeapi/v1.0/s3object/GetEmployeeImage?siteId=${widget
.siteId}&employeeId=${widget.employeeId}",
width: 100.0,
height: 100.0,
);
}
on SocketException catch(e){
return Image.asset(
"assets/images/logo.png",
width: 100.0,
height: 100.0,
);
}
Related
I've migrated to the new Google Mobile Ads package in Flutter. My interstitial works perfectly but my Native ad show a temporary ad over the majority of my screen before loading into my ListView Container awaiting it with a FutureBuilder. If I keep scrolling it eventually displays as desired. I'm not sure if this is just an issue with the simulator and a larger issue with my code. Here is an example of the issue... Also, I'm not sure if it's my xib file, but I'm using the 1 from the googleads-moble-flutter/NativeAds example HERE
Here is an example of my code....
Future futureAd;
#override
void initState() {
super.initState();
futureAd = adBuilder();
}
Future adBuilder() async {
// TODO: Create a NativeAd instance
final myAd = NativeAd(
adUnitId: NativeAd.testAdId,
factoryId: 'listTile',
request: AdRequest(keywords: ['kpop', 'music', 'youth']),
listener: AdListener(
onAdLoaded: (_) {
setState(() {
_isAdLoaded = true;
});
},
onAdFailedToLoad: (ad, error) {
// Releases an ad resource when it fails to load
ad.dispose();
setState(() {
_isAdLoaded = false;
});
print(
'NATIVE AD ERROR ---- Ad load failed (code=${error.code} message=${error.message})');
},
),
);
_ad = myAd;
_ad.load();
print(_isAdLoaded);
}
FutureBuilder(
future: futureAd,
// ignore: missing_return
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case (ConnectionState.none):
return Container();
case (ConnectionState.done):
return Container(
height: 300,
width:
MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.amberAccent,
borderRadius:
BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.grey,
blurRadius: 15,
offset: Offset(
4, 8), // Shadow position
),
],
),
child: (_isAdLoaded = true) ? AdWidget(ad: _ad) :
Image.asset('assets/loading.gif'),
);
case (ConnectionState.active):
return Container(
height: 300,
width: MediaQuery.of(context).size.width,
child: Image.asset('assets/loading.gif')
);
case (ConnectionState.waiting):
return Container(
height: 300,
width: MediaQuery.of(context).size.width,
child: Image.asset('assets/loading.gif')
);
default:
return Container(
height: 300,
width: MediaQuery.of(context).size.width,
child: Image.asset('logo500.jpeg')
);
}
},
),
I have upload an ios app developed with flutter on appstore for testing in testflight mode ,but it show white screen on some device when i used to test it ,but on some of the devices it worked fine, what will be the issue
This is my splash screen file
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(color: Colors.white),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 150,
),
Image.asset(
'image/asset/image.jpg',
width: 200,
height: 200,
),
SizedBox(
height: MediaQuery.of(context).size.height*0.2,//200
),
Image.asset(
'image/asset/adms.jpg',
width: 250,
height: 170,
)
],
),
),
),
);
}
}
How can I position widgets correctly?
I supposed the positioning should be by some template and not by the eye.
Lets say i want the white square will be in the top center of the black container, half inside the black container and half outside, How can i do this?
The code:
Positioned(
top: 80,
right: 30,
left: 30,
child: Container(
height: 200,
width: 400.0,
color: Colors.black,
child: Column(
children: <Widget>[],
),
),
),
Positioned(
top: 40,
child: Container(
height: 100.0,
width: 100.0,
color: Colors.white,
),
),
You can try like this
Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
top: 80,
right: 30,
left: 30,
child: Container(
height: 200,
width: 400.0,
color: Colors.black,
child: Column(
children: <Widget>[],
),
),
),
Positioned(
top: 40,
child: Container(
height: 100.0,
width: 100.0,
color: Colors.white,
),
),
],
)
I'm trying to put a glossy effect on a widget, sort of like how you would see on a Credit Card. I found another question about frosted glass, but that's not what I want.
I ended up using this Custom Clipper
class CardShinyClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
final path = Path();
path.lineTo(size.width, 0.0);
path.lineTo(size.width, size.height / 10);
path.lineTo(size.width / 10, size.height);
path.lineTo(0.0, size.height);
path.close();
return path;
}
#override
bool shouldReclip(CardShinyClipper oldClipper) => false;
}
With this as an item in the stack ontop of my card
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
),
alignment: AlignmentDirectional.center,
child: ClipPath(
clipper: CardShinyClipper(),
child: Container(
height: 200.0,
width: 300.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.grey.shade200.withOpacity(0.2),
),
),
),
),
Im trying to display the CircularProgressIndicator in my flutter app on click of button but it does not render the circular progress bar, but as soon as I change the code to use LinearProgressBar the progress bar comes without any issue. So wanted to know is there any special setting which I need to display the circular loading indicator?
Works
if (_isFetching) {
return new Scaffold(
body: new Center(
child: new SizedBox(
width: 40.0,
height: 40.0,
child: const LinearProgressIndicator(backgroundColor: Colors.black)),
));
}
Do not work
if (_isFetching) {
return new Scaffold(
body: new Center(
child: new SizedBox(
width: 40.0,
height: 40.0,
child: const CircularProgressIndicator(backgroundColor: Colors.black)),
));
}
Make sure the progress bar's value color is different from the parent widget's background color. Try this:
if (_isFetching) {
return Scaffold(
body: Center(
child: SizedBox(
width: 40.0,
height: 40.0,
child: const CircularProgressIndicator(
backgroundColor: Colors.black,
valueColor: AlwaysStoppedAnimation<Color>(Colors.red))),
));
}
You can refer to the docs here. You are using backgroundColor property which only defines background color of indicator and not the type of indicator. I'm using null for Indeterminate type. You can use valueColor[doc] property to change the color of indicator. Here is simple code and it works fine.
if (_isFetching) {
return new Scaffold(
body: new Center(
child: new SizedBox(
width: 40.0,
height: 40.0,
child:
const CircularProgressIndicator(
value: null,
strokeWidth: 2.0,
)),
));
}