import 'dart:ui'; import 'package:aitrainer_app/model/cache.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:bloc/bloc.dart'; import 'package:google_fonts/google_fonts.dart'; // ignore: must_be_immutable class ImageButton extends StatelessWidget { final String text; TextStyle style = TextStyle(fontSize: 14); final String image; double top; final double left; double height; double width; bool isShape; final Bloc bloc; final Alignment textAlignment; final VoidCallback onTap; bool isLocked; bool isMarked; int buttonIndex; ImageButton( {this.text, this.style, this.image, this.top, this.left, this.height, this.width, this.bloc, this.isShape, this.textAlignment, this.onTap, this.buttonIndex, this.isMarked, @required this.isLocked}) { width = width ?? 180; height = height ?? 180; isMarked = isMarked ?? false; style = style ?? GoogleFonts.archivoBlack( fontSize: 14, ); } @override Widget build(BuildContext context) { if (top == null) { top = height - (style.fontSize - 5) * text.length - 2 * left < 0 ? height - 2 * style.fontSize - 22 : height - style.fontSize - 37; //print("Top: " + top.toStringAsFixed(0) + " length: " + ((style.fontSize - 5) * text.length).toString()); } final double width = MediaQuery.of(context).size.width; //print("Mediawidth: " + width.toStringAsFixed(0)); return Stack(alignment: AlignmentDirectional.bottomStart, children: [ FlatButton( child: image == null ? _getButtonImage("asset/image/WT_menu_dark.jpg") : isMarked ? Stack( children: [ _getButtonImage(image), Container( width: width, height: height, child: BackdropFilter( filter: ImageFilter.blur(sigmaX: 1, sigmaY: 1), child: Container( color: Colors.black.withOpacity(0.3), ), ), ) ], ) : _getButtonImage(image), padding: EdgeInsets.only(left: 0.0, bottom: 0), shape: getShape(isShape), onPressed: onTap ?? onTap, ), Container( padding: EdgeInsets.all(4), child: InkWell( onTap: onTap ?? onTap, child: Text(text, maxLines: 2, style: GoogleFonts.archivoBlack( fontSize: 16, color: Colors.white, shadows: [ Shadow( offset: Offset(2.0, 2.0), blurRadius: 6.0, color: Colors.black54, ), Shadow( offset: Offset(-3.0, 3.0), blurRadius: 12.0, color: Colors.black54, ), ], )), )), isMarked == null || Cache().hasPurchased ? Offstage() : Stack(alignment: Alignment.topCenter, children: [ Positioned( top: 10, left: (width / 2 - 30) / 2 - 75, child: !isLocked ? Offstage() : GestureDetector( child: Image.asset( 'asset/image/lock.png', height: 50, width: 50, ), onTap: onTap ?? onTap, )) ]), isLocked == null ? Offstage() : Stack(alignment: Alignment.topCenter, children: [ Positioned( top: 10, left: (width / 2 - 30) / 2 - 75, child: isMarked ? GestureDetector( child: Image.asset( 'asset/image/haken.png', height: 70, width: 70, ), onTap: onTap ?? onTap, ) : Offstage(), ) ]), ] //) // ) ); } 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 + imageName; //.substring(11); Widget image = FadeInImage.assetNetwork(placeholder: 'asset/image/dots.gif', image: url, height: this.height); return image; }, */ ); } on Exception catch (_) { String url = Cache.mediaUrl + '/images/' + imageName; image = FadeInImage.assetNetwork( placeholder: 'asset/image/dots.gif', image: url, height: 50, ); } return image; } }