workouttest_app/lib/view/customer_goal_page.dart
2021-04-12 00:51:09 +02:00

162 lines
6.3 KiB
Dart

import 'dart:collection';
import 'package:aitrainer_app/bloc/customer_change/customer_change_bloc.dart';
import 'package:aitrainer_app/util/app_localization.dart';
import 'package:aitrainer_app/repository/customer_repository.dart';
import 'package:aitrainer_app/util/trans.dart';
import 'package:aitrainer_app/widgets/app_bar_min.dart';
import 'package:aitrainer_app/widgets/app_bar_progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.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> with Trans {
String? selected;
bool fulldata = false;
@override
Widget build(BuildContext context) {
setContext(context);
CustomerRepository customerRepository;
dynamic args = ModalRoute.of(context)!.settings.arguments;
if (args is HashMap && args['personal_data'] != null) {
fulldata = args['personal_data'];
customerRepository = args['bloc'];
} else {
customerRepository = ModalRoute.of(context)!.settings.arguments as CustomerRepository;
}
PreferredSizeWidget _bar = AppBarMin(
back: true,
);
if (!fulldata) {
_bar = AppBarProgress(max: 50, min: 26);
}
return Scaffold(
appBar: _bar,
body: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('asset/image/WT_light_background.jpg'),
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:
GoogleFonts.archivoBlack(color: Colors.orange, fontSize: 30, fontWeight: FontWeight.w900),
),
highlightColor: Colors.white,
),
Stack(alignment: Alignment.bottomLeft, children: [
TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(0.0),
shape: getShape(changeBloc, GoalsItem.muscle),
),
child: Image.asset(
"asset/image/Gain_muscle.jpg",
height: 180,
),
onPressed: () => {
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, children: [
TextButton(
style: TextButton.styleFrom(
padding: EdgeInsets.all(0.0),
shape: getShape(changeBloc, GoalsItem.weight),
),
child: Image.asset(
"asset/image/WT_weight_loss.jpg",
height: 180,
),
onPressed: () => {
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(),
ElevatedButton(
style: ElevatedButton.styleFrom(
onPrimary: Colors.white,
primary: Colors.orange,
),
child: Text(fulldata ? t("Save") : t("Next")),
onPressed: () => {
//changingViewModel.saveCustomer(),
changeBloc.add(CustomerSave()),
Navigator.of(context).pop(),
if (!fulldata) {Navigator.of(context).pushNamed("customerFitnessPage", arguments: changeBloc.customerRepository)}
},
)
],
),
));
}),
),
));
}
dynamic getShape(CustomerChangeBloc customerBloc, String goal) {
if (customerBloc.customerRepository.goal == null) return null;
String selectedGoal = customerBloc.customerRepository.goal!;
dynamic returnCode = (selectedGoal == goal)
? RoundedRectangleBorder(
side: BorderSide(width: 4, color: Colors.red),
)
: null;
//return
return returnCode;
}
}