136 lines
4.9 KiB
Dart
136 lines
4.9 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/auth.dart';
|
|
import 'package:aitrainer_app/model/workout_tree.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.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,
|
|
overflow: Overflow.visible,
|
|
children: [
|
|
FlatButton(
|
|
child: _getButtonImage(workoutTree),
|
|
padding: EdgeInsets.all(0.0),
|
|
onPressed:() =>
|
|
{
|
|
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 ( Auth().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") {
|
|
Navigator.of(context).pushNamed(
|
|
'exerciseCustomPage',
|
|
arguments: workoutTree.exerciseType),
|
|
} else {
|
|
Navigator.of(context).pushNamed(
|
|
'exerciseNewPage',
|
|
arguments: workoutTree.exerciseType),
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
),
|
|
InkWell(
|
|
child: Text(workoutTree.name, style: TextStyle(color: workoutTree.color, fontSize: workoutTree.fontSize, fontFamily: 'Arial', fontWeight: FontWeight.w900 ),),
|
|
highlightColor: workoutTree.color,
|
|
)]
|
|
)
|
|
)
|
|
)
|
|
);
|
|
});
|
|
//_columnChildren.add(Spacer(flex: 3));
|
|
SliverList sliverList =
|
|
SliverList(
|
|
delegate: SliverChildListDelegate(
|
|
_columnChildren
|
|
)
|
|
);
|
|
|
|
return sliverList;
|
|
}
|
|
|
|
dynamic _getButtonImage(WorkoutTree workoutTree) {
|
|
dynamic image;
|
|
/*String url = workoutTree.imageName;
|
|
if ( workoutTree.imageName.startsWith("https") ) {
|
|
image = FadeInImage.assetNetwork(
|
|
placeholder: 'asset/image/dots.gif',
|
|
image: url,
|
|
height: 180,
|
|
);
|
|
} else {
|
|
image = Image.asset(workoutTree.imageName, height: 180,);
|
|
}*/
|
|
|
|
try {
|
|
image = Image.asset(
|
|
workoutTree.imageName,
|
|
height: 180,
|
|
errorBuilder: (context, error, stackTrace) {
|
|
String url = Auth.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 = Auth.mediaUrl + '/images/' + workoutTree.imageName;
|
|
image = FadeInImage.assetNetwork(
|
|
placeholder: 'asset/image/dots.gif',
|
|
image: url,
|
|
height: 180,
|
|
);
|
|
}
|
|
|
|
return image;
|
|
}
|
|
} |