149 lines
4.8 KiB
Dart
149 lines
4.8 KiB
Dart
import 'dart:ui';
|
|
|
|
import 'package:aitrainer_app/bloc/menu/menu_bloc.dart';
|
|
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/model/cache.dart';
|
|
import 'package:aitrainer_app/model/workout_tree.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/painting.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
// ignore: must_be_immutable
|
|
class MenuPageWidget extends StatelessWidget {
|
|
int parent;
|
|
|
|
MenuPageWidget({this.parent});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
MenuBloc menuBloc = BlocProvider.of<MenuBloc>(context);
|
|
|
|
return CustomScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
slivers: <Widget>[buildMenuColumn(parent, context, menuBloc)]);
|
|
}
|
|
|
|
SliverList buildMenuColumn(
|
|
int parent, BuildContext context, MenuBloc menuBloc) {
|
|
final List<Widget> _columnChildren = List();
|
|
|
|
menuBloc.menuTreeRepository
|
|
.getBranch(menuBloc.parent)
|
|
.forEach((treeName, value) {
|
|
WorkoutTree workoutTree = value as WorkoutTree;
|
|
_columnChildren.add(Container(
|
|
padding: EdgeInsets.only(top: 16.0),
|
|
child: Center(
|
|
child: Stack(
|
|
alignment: Alignment.bottomLeft,
|
|
//clipBehavior: Clip.antiAliasWithSaveLayer,
|
|
children: [
|
|
FlatButton(
|
|
child: _getButtonImage(workoutTree),
|
|
padding: EdgeInsets.only(left: 0.0, bottom: 0),
|
|
shape: getShape(workoutTree),
|
|
onPressed: () => menuClick(workoutTree, menuBloc, context),
|
|
),
|
|
Positioned(
|
|
top: workoutTree.name.length > 15 ? 140 : 150,
|
|
left: 5,
|
|
child: Container(
|
|
height: 300,
|
|
width: 280,
|
|
child: InkWell(
|
|
onTap:() => menuClick(workoutTree, menuBloc, context),
|
|
child: Text(
|
|
" " + workoutTree.name,
|
|
maxLines: 2,
|
|
style: TextStyle(
|
|
color: workoutTree.color,
|
|
fontSize: workoutTree.fontSize,
|
|
fontFamily: 'Arial',
|
|
fontWeight: FontWeight.w900),
|
|
),
|
|
|
|
highlightColor: workoutTree.color,
|
|
),
|
|
color: Colors.transparent,
|
|
),
|
|
),
|
|
|
|
]
|
|
)
|
|
)
|
|
)
|
|
);
|
|
});
|
|
|
|
SliverList sliverList =
|
|
SliverList(delegate: SliverChildListDelegate(_columnChildren));
|
|
|
|
return sliverList;
|
|
}
|
|
|
|
void menuClick(
|
|
WorkoutTree workoutTree, MenuBloc menuBloc, BuildContext context) {
|
|
print("Hi!, Menu clicked " + workoutTree.id.toString());
|
|
if (workoutTree.child == false) {
|
|
menuBloc.add(MenuTreeDown(parent: workoutTree.id));
|
|
} else {
|
|
menuBloc.add(MenuClickExercise(exerciseTypeId: workoutTree.id));
|
|
if (Cache().userLoggedIn == null) {
|
|
Scaffold.of(context).showSnackBar(SnackBar(
|
|
backgroundColor: Colors.orange,
|
|
content: Text(
|
|
AppLocalizations.of(context).translate('Please log in'),
|
|
style: TextStyle(color: Colors.white))));
|
|
} else {
|
|
if (workoutTree.exerciseType.name == "Custom" && Cache().userLoggedIn.admin == 1) {
|
|
Navigator.of(context).pushNamed('exerciseCustomPage',
|
|
arguments: workoutTree.exerciseType);
|
|
} else {
|
|
Navigator.of(context).pushNamed('exerciseNewPage',
|
|
arguments: workoutTree.exerciseType);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
dynamic getShape(WorkoutTree workoutTree) {
|
|
bool base = workoutTree.base;
|
|
dynamic returnCode = (base == true)
|
|
? RoundedRectangleBorder(
|
|
side: BorderSide(width: 4, color: Colors.orangeAccent),
|
|
)
|
|
: null;
|
|
return returnCode;
|
|
}
|
|
|
|
dynamic _getButtonImage(WorkoutTree workoutTree) {
|
|
dynamic image;
|
|
try {
|
|
image = Image.asset(
|
|
workoutTree.imageName,
|
|
height: 180,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
String url =
|
|
Cache.mediaUrl + 'images/' + workoutTree.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/' + workoutTree.imageName;
|
|
image = FadeInImage.assetNetwork(
|
|
placeholder: 'asset/image/dots.gif',
|
|
image: url,
|
|
height: 180,
|
|
);
|
|
}
|
|
|
|
return image;
|
|
}
|
|
}
|