163 lines
5.3 KiB
Dart
163 lines
5.3 KiB
Dart
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/model/auth.dart';
|
|
import 'package:aitrainer_app/model/exercise_type.dart';
|
|
import 'package:aitrainer_app/model/workout_tree.dart';
|
|
import 'package:aitrainer_app/util/common.dart';
|
|
import 'package:aitrainer_app/util/menu_tests.dart';
|
|
import 'package:aitrainer_app/viewmodel/exercise_changing_view_model.dart';
|
|
import 'package:aitrainer_app/widgets/bottom_nav.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'dart:collection';
|
|
import 'package:provider/provider.dart';
|
|
|
|
// ignore: must_be_immutable
|
|
class MenuPage extends StatefulWidget {
|
|
_MenuPageState _state;
|
|
static const routeName = '/menu_page';
|
|
int parent;
|
|
|
|
MenuPage({this.parent});
|
|
|
|
@override
|
|
_MenuPageState createState() {
|
|
_state = new _MenuPageState();
|
|
return _state;
|
|
}
|
|
|
|
}
|
|
|
|
class _MenuPageState extends State<MenuPage> {
|
|
final BottomNavigator bottomNav = BottomNavigator();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final MenuTests menu = MenuTests(context);
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: <Widget>[
|
|
Text(AppLocalizations.of(context).translate("Tests")),
|
|
Image.asset(
|
|
'asset/image/WT_long_logo.png',
|
|
fit: BoxFit.cover,
|
|
height: 65.0,
|
|
),
|
|
],
|
|
),
|
|
leading: IconButton(
|
|
icon: Icon(Icons.arrow_back, color: Colors.white),
|
|
onPressed: () => {
|
|
this.setState(() {
|
|
widget.parent = 0;
|
|
},
|
|
)},
|
|
),
|
|
),
|
|
|
|
body: Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage('asset/image/WT_menu_dark.png'),
|
|
fit: BoxFit.fill,
|
|
alignment: Alignment.center,
|
|
),
|
|
),
|
|
|
|
child: CustomScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
slivers: <Widget>[
|
|
buildMenuColumn(widget.parent, context, menu)
|
|
]
|
|
)
|
|
),
|
|
);
|
|
}
|
|
|
|
SliverList buildMenuColumn(int parent, BuildContext context, MenuTests menu) {
|
|
LinkedHashMap tree = menu.getMenuItems();
|
|
List<Widget> _columnChildren = List();
|
|
ExerciseType exerciseType;
|
|
ExerciseChangingViewModel model = Provider.of<ExerciseChangingViewModel>(context, listen: false);
|
|
|
|
tree.forEach((treeName, value) {
|
|
WorkoutTree workoutTree = value as WorkoutTree;
|
|
|
|
if ( workoutTree.parent == parent ) {
|
|
_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 ) {
|
|
this.setState(() {
|
|
widget.parent = workoutTree.id;
|
|
},
|
|
),
|
|
} else {
|
|
exerciseType = Common.getExerciseType(workoutTree.exerciseTypeId),
|
|
model.setExerciseType(exerciseType),
|
|
model.setCustomer(Auth().userLoggedIn),
|
|
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 {
|
|
Navigator.of(context).pushNamed('exerciseNewPage'),
|
|
}
|
|
}
|
|
|
|
}
|
|
),
|
|
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;
|
|
if ( workoutTree.imageName.startsWith("http") ) {
|
|
image = FadeInImage.assetNetwork(
|
|
image: workoutTree.imageName,
|
|
placeholder: 'asset/image/dots.gif',
|
|
//imageScale: 0.1,
|
|
height: 180,
|
|
placeholderScale: 0.1,
|
|
);
|
|
} else {
|
|
image = Image.asset(workoutTree.imageName, height: 180,);
|
|
}
|
|
return image;
|
|
}
|
|
|
|
}
|