workouttest_app/lib/view/customer_goal_page.dart
2020-08-17 12:38:47 +02:00

178 lines
7.3 KiB
Dart

import 'package:aitrainer_app/bloc/customer_change/customer_change_bloc.dart';
import 'package:aitrainer_app/localization/app_localization.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_form_bloc/flutter_form_bloc.dart';
class GoalsItem {
static String muscle = "gain_muscle";
static String weight = "weight_loss";
}
// ignore: must_be_immutable
class CustomerGoalPage extends StatefulWidget {
@override
State<StatefulWidget> createState() => _CustomerGoalPage();
}
class _CustomerGoalPage extends State<CustomerGoalPage> {
String selected;
@override
Widget build(BuildContext context) {
final double cWidth = MediaQuery.of(context).size.width * 0.75;
final CustomerRepository customerRepository =
ModalRoute.of(context).settings.arguments;
return Scaffold(
appBar: AppBar(
title: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Image.asset(
'asset/image/WT_long_logo.png',
fit: BoxFit.cover,
height: 65.0,
),
],
),
backgroundColor: Colors.transparent,
),
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.png'),
fit: BoxFit.cover,
alignment: Alignment.center,
),
),
height: double.infinity,
width: double.infinity,
child: BlocProvider(
create: (context) =>
CustomerChangeBloc(customerRepository: customerRepository),
child: Builder(builder: (context) {
CustomerChangeBloc changeBloc =
BlocProvider.of<CustomerChangeBloc>(context);
return SingleChildScrollView(
child: Center(
child: Column(
children: [
Divider(),
InkWell(
child: Text(
AppLocalizations.of(context)
.translate("Set Your Goals"),
style: TextStyle(
color: Colors.orange,
fontSize: 50,
fontFamily: 'Arial',
fontWeight: FontWeight.w900),
),
highlightColor: Colors.white,
),
Stack(
alignment: Alignment.bottomLeft,
overflow: Overflow.visible,
children: [
FlatButton(
child: Image.asset(
"asset/image/WT_gain_muscle.png",
height: 180,
),
padding: EdgeInsets.all(0.0),
shape: getShape(changeBloc, GoalsItem.muscle),
onPressed: () => {
print("gain muscle"),
setState((){
selected = GoalsItem.muscle;
changeBloc.add(CustomerGoalChange(goal: GoalsItem.muscle));
}),
}),
InkWell(
child: Text(
AppLocalizations.of(context)
.translate("Gain Muscle"),
style: TextStyle(
color: Colors.white,
fontSize: 32,
fontFamily: 'Arial',
fontWeight: FontWeight.w900),
),
highlightColor: Colors.white,
)
]),
Divider(),
Stack(
alignment: Alignment.bottomLeft,
overflow: Overflow.visible,
children: [
FlatButton(
child: Image.asset(
"asset/image/WT_weight_loss.png",
height: 180,
),
padding: EdgeInsets.all(0.0),
shape: getShape(changeBloc, GoalsItem.weight),
onPressed: () => {
print("weight_loss"),
setState((){
selected = GoalsItem.muscle;
changeBloc.add(CustomerGoalChange(goal: GoalsItem.weight));
}),
}),
InkWell(
child: Text(
AppLocalizations.of(context)
.translate("Loose Weight"),
style: TextStyle(
color: Colors.white,
fontSize: 32,
fontFamily: 'Arial',
fontWeight: FontWeight.w900),
),
highlightColor: Colors.white,
)
]),
Divider(),
RaisedButton(
color: Colors.orange,
textColor: Colors.white,
child: InkWell(
child: Text(
AppLocalizations.of(context).translate("Next"))),
onPressed: () => {
//changingViewModel.saveCustomer(),
changeBloc.add(CustomerSave()),
Navigator.of(context).pop(),
Navigator.of(context).pushNamed("customerFitnessPage",
arguments: changeBloc.customerRepository)
},
)
],
),
));
}),
),
));
}
dynamic getShape(CustomerChangeBloc customerBloc, String goal) {
String selectedGoal = customerBloc.customerRepository.goal;
dynamic returnCode = (selectedGoal == goal)
? RoundedRectangleBorder(
side: BorderSide(width: 4, color: Colors.red),
)
: null;
//return
return returnCode;
}
}