Tutorial and code of Height Slider in Flutter. Copy and paste the below code as per your requirements.
height_slider: ^1.3.2
import 'package:flutter/material.dart';
import 'package:height_slider/height_slider.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Height Slider',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(
title: 'Height Slider',
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int height = 170;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(child: Text(widget.title),),
),
body: Center(
child: HeightSlider(
height: height,
onChange: (val) => setState(() => height = val),
unit: 'cm', // optional
),
),
);
}
}