slider.1.dart 1.24 KB
Newer Older
1 2 3 4
// 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.

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

import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
17 18 19
      theme: ThemeData(
        colorSchemeSeed: const Color(0xff6750a4),
        useMaterial3: true,
20
      ),
21
      home: const SliderExample(),
22 23 24 25
    );
  }
}

26 27
class SliderExample extends StatefulWidget {
  const SliderExample({super.key});
28 29

  @override
30
  State<SliderExample> createState() => _SliderExampleState();
31 32
}

33 34
class _SliderExampleState extends State<SliderExample> {
  double _currentSliderValue = 20;
35 36 37

  @override
  Widget build(BuildContext context) {
38 39 40 41 42 43 44 45 46 47 48 49 50
    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;
          });
        },
      ),
51 52 53
    );
  }
}