Skip to content

Instantly share code, notes, and snippets.

@kotrotko
Created August 2, 2021 10:25
Show Gist options
  • Save kotrotko/92551650dc1ed0aed9f4b434e179a639 to your computer and use it in GitHub Desktop.
Save kotrotko/92551650dc1ed0aed9f4b434e179a639 to your computer and use it in GitHub Desktop.
An example of the original code for an interview
//Screen to manage MAP and Description forms
import 'dart:collection';
import 'package:flutter/material.dart';
import 'package:flutter_map_live1/ui/widgets/seller_input/input_map_seller.dart';
import 'package:flutter_map_live1/ui/widgets/seller_input/input_description_seller.dart';
import 'package:flutter_map_live1/ui/widgets/seller_input/input_upload_seller.dart';
class StepperPage extends StatefulWidget {
StepperPage({Key? key, required this.title}) : super (key: key);
final String title;
@override
_StepperPageState createState() => _StepperPageState();
}
class _StepperPageState extends State<StepperPage> {
int currentStep = 0;
GlobalKey<FormState> _formKey = new GlobalKey<FormState>();
static final pointController = TextEditingController();
@override
Widget build(BuildContext context) {
var mapData = HashMap<String, String>();
mapData["seller_point"] = SellerMapInputState.pointController.text;
mapData["seller_name"] = SellerDescriptionInputState.nameController.text;
mapData["seller_type"] = SellerDescriptionInputState.typeController.text;
mapData["seller_transaction"] = SellerDescriptionInputState.transactionController.text;
List<Step> steps = [
Step(
title: Text('LatLng'),
content: SellerMapInput(),
state: currentStep == 0 ? StepState.editing : StepState.indexed,
isActive: true,
),
Step(
title: Text('Description'),
content: SellerDescriptionInput(),
state: currentStep == 1 ? StepState.editing : StepState.indexed,
isActive: true,
),
Step(
title: Text('Upload'),
content: Upload(mapData),
state: StepState.complete,
isActive: true,
)
];
return Scaffold(
body: Column(
children: <Widget>[
SizedBox(
height: 20.0,
),
Expanded(
child: Stepper(
controlsBuilder: (BuildContext context,
{VoidCallback? onStepContinue, VoidCallback? onStepCancel}) {
if (currentStep < steps.length - 1) {
return Row(
children: <Widget>[
TextButton(
onPressed: onStepContinue,
child: const Text('NEXT'),
),
TextButton(
onPressed: onStepCancel,
child: const Text('CANCEL'),
),
],);
} else { return Row();}
},
currentStep: this.currentStep,
steps: steps,
type: StepperType.horizontal,
onStepTapped: (step) {
setState(() {
currentStep = step;
});
},
onStepContinue: (){
setState(() {
if (currentStep < steps.length - 1) {
if (currentStep == 0 && SellerMapInputState.formKey.currentState!.validate()){
currentStep = currentStep + 1;
} else if (currentStep == 1 && SellerDescriptionInputState.formKey.currentState!.validate()) {
currentStep = currentStep + 1;
} else {
currentStep = 0;
}
}
});
}
),
),
]
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment