slider.0.dart 1.13 KB
Newer Older
1 2 3 4 5 6
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';

7 8
/// Flutter code sample for [Slider].

9
void main() => runApp(const SliderApp());
10

11 12
class SliderApp extends StatelessWidget {
  const SliderApp({super.key});
13 14 15

  @override
  Widget build(BuildContext context) {
16 17
    return const MaterialApp(
      home: SliderExample(),
18 19 20 21
    );
  }
}

22 23
class SliderExample extends StatefulWidget {
  const SliderExample({super.key});
24 25

  @override
26
  State<SliderExample> createState() => _SliderExampleState();
27 28
}

29
class _SliderExampleState extends State<SliderExample> {
30 31 32 33
  double _currentSliderValue = 20;

  @override
  Widget build(BuildContext context) {
34 35 36 37 38 39 40 41 42 43 44 45 46
    return Scaffold(
      appBar: AppBar(title: const Text('Slider')),
      body: Slider(
        value: _currentSliderValue,
        max: 100,
        divisions: 5,
        label: _currentSliderValue.round().toString(),
        onChanged: (double value) {
          setState(() {
            _currentSliderValue = value;
          });
        },
      ),
47 48 49
    );
  }
}