workouttest_app/lib/widgets/image_button.dart
2020-10-21 21:24:43 +02:00

126 lines
3.1 KiB
Dart

import 'package:aitrainer_app/model/cache.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:bloc/bloc.dart';
class ImageButton extends StatelessWidget {
final String text;
final TextStyle style;
final String image;
final double top;
final double left;
final double height;
final double width;
final bool isShape;
final Bloc bloc;
final Alignment textAlignment;
final VoidCallback onTap;
bool isLocked;
ImageButton({
this.text,
this.style,
this.image,
this.top,
this.left,
this.height,
this.width,
this.bloc,
this.isShape,
this.textAlignment,
this.onTap,
@required this.isLocked
});
@override
Widget build(BuildContext context) {
return Stack(
//alignment: textAlignment,
fit: StackFit.passthrough,
overflow: Overflow.clip,
children: [
FlatButton(
child: image == null ?
_getButtonImage("asset/image/WT_menu_dark.png") :
_getButtonImage(image),
padding: EdgeInsets.only(left: 0.0, bottom: 0),
shape: getShape(isShape),
onPressed: onTap ?? onTap,
),
Stack(
alignment: Alignment.topLeft,
children: [
Positioned(
top: 50,
left: 50,
child: this.isLocked?
Image.asset(
'asset/image/lock.png',
height: 60,
width: 60,
)
: Container(),
)]
),
Positioned(
top: text.length > 20 ? 140 : 160,
left: left,
child: Container(
height: 200,
width: 180,
child: InkWell(
onTap: onTap ?? onTap,
child: Text(
text,
maxLines: 2,
style: style,
),
),
color: Colors.transparent,
),
),
]
//)
// )
);
}
dynamic getShape(bool isShape) {
dynamic returnCode = (isShape == true)
? RoundedRectangleBorder(
side: BorderSide(width: 4, color: Colors.orangeAccent),
)
: null;
return returnCode;
}
dynamic _getButtonImage(String imageName) {
dynamic image;
try {
image = Image.asset(
imageName,
fit: BoxFit.fitWidth,
alignment: Alignment.center,
errorBuilder: (context, error, stackTrace) {
String url = Cache.mediaUrl + 'images/' + imageName.substring(11);
Widget image = FadeInImage.assetNetwork(
placeholder: 'asset/image/dots.gif',
image: url,
height: 180,
);
return image;
},
);
} on Exception catch (_) {
String url = Cache.mediaUrl + '/images/' + imageName;
image = FadeInImage.assetNetwork(
placeholder: 'asset/image/dots.gif',
image: url,
height: 180,
);
}
return image;
}
}