是否有可能在flutter中有这样的小部件

时间:2019-09-26 16:00:08

标签: flutter dart

在flutter中是否有任何内置的小部件来实现像(下图中的红色边框)这样的小部件?

我们可以拖动它来更改值。

finger slider

2 个答案:

答案 0 :(得分:1)

那只是具有预定高度的水平ListView

SizedBox(
  height: 56, // height of ListView
  child: ListView.builder(
    scrollDirection: Axis.horizontal, // makes it scroll in horizontal direction
    itemBuilder: (_, index) {
      // build your years 
    },
  ),
)

答案 1 :(得分:0)

可以使用ListView带来所需的输出。 Flutter刚刚在ListView上上传了一个视频,您可以在其中找到答案: https://www.youtube.com/watch?v=KJpkjHGiI5A

示例代码:

    import 'package:flutter/material.dart';

void main() => runApp(MyApp());
bool change ;
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  int i=0;
void fxn(){
  setState(() {
    i++;
  });
}
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('List View'),),
    body:  ListView.builder(
      itemCount: 30,
      itemBuilder: (_, index)=>Padding(
        padding: const EdgeInsets.fromLTRB(0, 270, 0, 270),
        child: MaterialButton(
          child: 

            Text('200$index',style: TextStyle(fontSize: 25),),
            onPressed: (){
            },
            color: Colors.white70,
        ),
      ),

      scrollDirection: Axis.horizontal,


    )
    );
  }
}

输出:Output