Cara Membuat Stepper Widget di Flutter

1 month ago 44
Cara Membuat Stepper Widget di Flutter
Cara Membuat Stepper Widget di Flutter

Halo sobat 48 😁. Bagaimana kabarnya? Semoga selalu dalam keadaan sehat ya. Pada kesempatan kali ini saya akan membagikan sebuah artikel yang membahas tentang Cara Membuat Stepper Widget di Flutter.

Berikut ini root codification nya:

import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { instrumentality 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) { instrumentality 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, _) { instrumentality 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 nexus Sociabuzz dibawah ini :

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_

Read Entire Article