Cara Membuat Stepper Widget di Flutter |
Berikut ini source code nya:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
useMaterial3: false,
primarySwatch: Colors.green,
),
home: const HomePage(),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({super.key});
@override
HomePageState createState() => HomePageState();
}
class HomePageState extends State {
int currentStep = 0;
bool isVerticalStepper = true;
stepTapped(int step) {
setState(() => currentStep = step);
}
stepContinue() {
currentStep < 2 ? setState(() => currentStep += 1) : null;
}
stepCancel() {
currentStep > 0 ? setState(() => currentStep -= 1) : null;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Stepper Flutter'),
),
body: Column(
children: [
SwitchListTile(
title: const Text('Switch Stepper'),
subtitle: const Text('vertical/horizontal direction'),
value: isVerticalStepper,
onChanged: (_) {
setState(() {
isVerticalStepper = !isVerticalStepper;
});
}),
const Divider(
thickness: 2,
height: 30,
),
Expanded(
child: Stepper(
type: isVerticalStepper
? StepperType.vertical
: StepperType.horizontal,
physics: const ScrollPhysics(),
currentStep: currentStep,
onStepTapped: (step) => stepTapped(step),
controlsBuilder: (context, _) {
return Row(
children: [
TextButton(
onPressed: () {
stepContinue();
},
child: const Text(
'Berikutnya',
style:
TextStyle(color: Colors.green),
),
),
TextButton(
onPressed: () {
stepCancel();
},
child: const Text(
'Batal',
style:
TextStyle(color: Colors.grey),
),
),
],
);
},
steps: [
Step(
title: const Text('Nama'),
content: Column(
children: [
TextFormField(
decoration:
const InputDecoration(
labelText: 'Nama Anda'
),
),
],
),
isActive: currentStep >= 0,
state: currentStep >= 0
? StepState.complete
: StepState.disabled,
),
Step(
title: const Text('Telp'),
content: Column(
children: [
TextFormField(
decoration: const InputDecoration(
labelText: 'No. Telp'
),
),
],
),
isActive: currentStep >= 0,
state: currentStep >= 1
? StepState.complete
: StepState.disabled,
),
Step(
title: const Text('Alamat'),
content: Column(
children: [
TextFormField(
decoration: const InputDecoration(
labelText: 'Alamat Lengkap'
),
),
],
),
isActive: currentStep >= 0,
state: currentStep >= 2
? StepState.complete
: StepState.disabled,
),
],
),
),
],
),
);
}
}
Untuk Output-nya nanti seperti ini:Support Blog Rivaldi 48 agar terus bisa membagikan artikel-artikel yang bermanfaat dengan cara klik link Sociabuzz dibawah ini :https://sociabuzz.com/azharrvldi_/donate (bisa pakai GoPay, OVO, DANA, Bank Transfer)
Demikian informasi yang saya bagikan untuk kalian. Jangan lupa bagikan artikel ini ke teman-teman kalian agar ikut membaca Cara Membuat Stepper Widget di Flutter ini. Subscribe juga blog Rivaldi 48 ini agar kalian mendapatkan notifikasi saat Admin update artikel terbaru. Semoga kalian lebih nyaman dan mudah dalam mengakses Blog Rivaldi 48 dimanapun kalian berada. Terima Kasih. Follow Instagram Admin @azhardvls_
0 Comments
Post a Comment
Silahkan tinggalkan komentar jika Anda punya saran, kritik, atau pertanyaan seputar topik pembahasan. Gunakan bahasa yang bijak dan santun. Terima Kasih.