올려 진 버튼을 누를 때 버튼 내의 텍스트 아래에 슬라이더를 추가하는 방법은 무엇입니까?

아룬 발라지

내 앱이 시작되면 바로 버튼이 표시됩니다. 이 버튼을 누르 자마자 같은 버튼 안에 슬라이더를 만들어이 사운드의 볼륨을 조절하고 싶습니다.

내가 필요한 것은 볼륨을 제어하는 ​​메커니즘이 아니라이 슬라이더를 표시하는 것입니다.

내가 달성하고 싶은 것은 여기 ..

내 버튼 코드

void main() => runApp(Home());
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
  title: "RelaX",
  home: Container(
    child: Scaffold(
      appBar: AppBar(
        elevation: 20.0,
        backgroundColor: Color(0xFF001E3D),
        title: Text(
          'Relax',
          style: GoogleFonts.raleway(
            fontSize: 30.0,
            color: Color(0xFF55b9f3),
          ),
        ),
        centerTitle: true,
      ),
      body: Column(
        children: <Widget>[
          RaisedButton(
              child: Text("View Slider"),
              onPressed: () => print("view slider")),
        ],
      ),
    ),
  ),
);
}
} 
Bluenile

가시성 위젯을 사용하여 슬라이더의 가시성을 설정할 수 있습니다. 아래 코드를 참조하십시오. RaisedButton과 동일한 효과를 얻기 위해 Inkwell과 함께 Container를 사용하고 있습니다.

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _currentSliderValue = 0;
  bool _sliderVisible = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Raised Button"),
      ),
      body: Center(
        child: ClipRRect(
          borderRadius: const BorderRadius.all(
            Radius.circular(20),
          ),
          child: Container(
            decoration: BoxDecoration(
              color: Colors.blue[200],
              borderRadius: const BorderRadius.all(
                Radius.circular(20),
              ),
            ),
            child: Material(
              elevation: 2,
              child: InkWell(
                onTap: () {
                  setState(() {
                    _sliderVisible = !_sliderVisible;
                  });
                },
                child: Container(
                  width: 125.0,
                  height: 125.0,
                  child: Column(
                    children: [
                      const SizedBox(
                        height: 15,
                      ),
                      Icon(
                        Icons.nightlight_round,
                        color: Colors.indigo[900],
                        size: 48,
                      ),
                      const SizedBox(
                        height: 5,
                      ),
                      Visibility(
                        visible: _sliderVisible,
                        child: Slider(
                          value: _currentSliderValue,
                          min: 0,
                          max: 10,
                          onChanged: (double value) {
                            setState(() {
                              _currentSliderValue = value;
                            });
                          },
                          activeColor: Colors.indigo[900],
                          inactiveColor: Colors.indigo[900],
                        ),
                      )
                    ],
                  ),
                ),
              ),
              color: Colors.transparent,
            ),
          ),
        ),
      ),
    );
  }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

Related 관련 기사

뜨겁다태그

보관