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/model/fitness_state.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/rendering.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; // ignore: must_be_immutable class CustomerFitnessPage extends StatefulWidget { late _CustomerFitnessPageState _state; _CustomerFitnessPageState createState() { _state = _CustomerFitnessPageState(); return _state; } } // dropbox for professional sport class _CustomerFitnessPageState extends State with Trans { late String selected; bool fulldata = false; @override Widget build(BuildContext context) { setContext(context); final double cWidth = MediaQuery.of(context).size.width * 0.75; 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; } selected = customerRepository.customer.fitnessLevel!; PreferredSizeWidget _bar = AppBarMin( back: true, ); if (!fulldata) { _bar = AppBarProgress(max: 50, min: 26); } return Scaffold( appBar: _bar, body: BlocProvider( create: (context) => CustomerChangeBloc(customerRepository: customerRepository), child: Builder(builder: (context) { // ignore: close_sinks CustomerChangeBloc changeBloc = BlocProvider.of(context); return SingleChildScrollView( scrollDirection: Axis.vertical, child: Container( padding: EdgeInsets.only(bottom: 200), decoration: BoxDecoration( image: DecorationImage( image: AssetImage('asset/image/WT_light_background.jpg'), fit: BoxFit.cover, alignment: Alignment.center, ), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Divider(), Wrap( //runAlignment: WrapAlignment.center, alignment: WrapAlignment.center, children: [ Text( t("Your Fitness State"), textAlign: TextAlign.center, style: TextStyle(color: Colors.orange, fontSize: 42, fontFamily: 'Arial', fontWeight: FontWeight.w900), ) ]), Divider(), TextButton( style: TextButton.styleFrom( padding: EdgeInsets.all(10.0), shape: getShape(customerRepository, FitnessState.beginner), ), child: Container( width: cWidth, child: Column( children: [ Text(t("Beginner"), textWidthBasis: TextWidthBasis.longestLine, style: TextStyle(color: Colors.blue, fontSize: 32, fontFamily: 'Arial', fontWeight: FontWeight.w900)), Text( t("I am beginner"), style: TextStyle(color: Colors.black, fontSize: 20, fontFamily: 'Arial', fontWeight: FontWeight.w100), ), ], )), onPressed: () => { setState(() { selected = FitnessState.beginner; changeBloc.add(CustomerFitnessChange(fitness: selected)); }), }), Divider(), TextButton( style: TextButton.styleFrom( padding: EdgeInsets.all(10.0), shape: getShape(customerRepository, FitnessState.intermediate), ), child: Container( width: cWidth, child: Column( children: [ InkWell( child: Text( t("Intermediate"), style: TextStyle(color: Colors.blue, fontSize: 32, fontFamily: 'Arial', fontWeight: FontWeight.w900), ), highlightColor: Colors.white, ), InkWell( child: Text( t("I am intermediate"), style: TextStyle(color: Colors.black, fontSize: 20, fontFamily: 'Arial', fontWeight: FontWeight.w100), ), highlightColor: Colors.white, ), ], ), ), onPressed: () => { setState(() { selected = FitnessState.intermediate; changeBloc.add(CustomerFitnessChange(fitness: selected)); print(selected); }), }), Divider(), TextButton( style: TextButton.styleFrom( padding: EdgeInsets.all(10.0), shape: getShape(customerRepository, FitnessState.advanced), ), child: Container( width: cWidth, child: Column( children: [ InkWell( child: Text( t("Advanced"), style: TextStyle(color: Colors.blue, fontSize: 32, fontFamily: 'Arial', fontWeight: FontWeight.w900), ), highlightColor: Colors.white, ), InkWell( child: Text( t("I am advanced"), style: TextStyle(color: Colors.black, fontSize: 20, fontFamily: 'Arial', fontWeight: FontWeight.w100), ), highlightColor: Colors.white, ), ], ), ), onPressed: () => { setState(() { selected = FitnessState.advanced; changeBloc.add(CustomerFitnessChange(fitness: selected)); print(selected); }), }), Divider(), TextButton( style: TextButton.styleFrom( padding: EdgeInsets.all(10.0), shape: getShape(customerRepository, FitnessState.professional), ), child: Container( width: cWidth, child: Column( children: [ InkWell( child: Text( AppLocalizations.of(context)!.translate("Professional"), style: TextStyle(color: Colors.blue, fontSize: 32, fontFamily: 'Arial', fontWeight: FontWeight.w900), ), highlightColor: Colors.white, ), InkWell( child: Text( AppLocalizations.of(context)!.translate("I am professional"), style: TextStyle(color: Colors.black, fontSize: 20, fontFamily: 'Arial', fontWeight: FontWeight.w100), ), highlightColor: Colors.white, ), ], ), ), onPressed: () => { setState(() { selected = FitnessState.professional; changeBloc.add(CustomerFitnessChange(fitness: selected)); print(selected); }), }), Divider(), ElevatedButton( style: ElevatedButton.styleFrom( onPrimary: Colors.white, primary: Colors.orange, ), child: Text(fulldata ? t("Save") : t("Next")), onPressed: () => { changeBloc.add(CustomerSave()), Navigator.of(context).pop(), if (!fulldata) {Navigator.of(context).pushNamed("customerBodyTypePage", arguments: customerRepository)} }, ) ], ), ), ); }))); } dynamic getShape(CustomerRepository customerRepository, String fitnessLevel) { String selected = customerRepository.fitnessLevel!; dynamic returnCode = (selected == fitnessLevel) ? RoundedRectangleBorder( side: BorderSide(width: 4, color: Colors.orange), ) : RoundedRectangleBorder( side: BorderSide(width: 1, color: Colors.blue), ); //return return returnCode; } }