【问题标题】:Flutter - Listview scroll behind another widgetFlutter - Listview 在另一个小部件后面滚动
【发布时间】:2021-06-03 14:48:28
【问题描述】:

我正在 Flutter 中尝试预约视图。所有小部件最初放置正常,但是当我滚动列表视图(可用时间列表)时,滚动动画会干扰放置在其顶部的元素(日历)。我知道我可以使用下拉列表,但我更喜欢列表。我已经尝试了 StackOverflow 的几个想法,但仍然无法使其正常工作

图片供参考:

how it looks when started

after start scrolling

    //simple calender
import 'package:flutter/material.dart';
import 'package:hswebapp/days.dart';
import 'package:hswebapp/hours.dart';
import 'package:table_calendar/table_calendar.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Appointment view',
      theme: ThemeData(

        primarySwatch: Colors.purple,
      ),
      home: MyHomePage(title: 'Appointment view'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  CalendarFormat _calendarFormat = CalendarFormat.twoWeeks;
  DateTime _focusedDay = DateTime.now();
  DateTime? _selectedDay;
  DateTime kFirstDay = DateTime.utc(2021, 1, 15);
  DateTime kLastDay = DateTime.utc(2022, 1, 20);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
        appBar: AppBar(
          title: Text('TableCalendar - Basics'),
        ),
        body: SafeArea(
          child: Column(

          children: <Widget>[
            daysCalender(),
            Text("Available Hours"),
            const SizedBox(
                height: 10,
              ),
          SingleChildScrollView(
          child: Container(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(
                  height: 150,
                  child: 
            AvailableHours(),
                )
          ],
        ) // your column1
      ),
    ),
            TextFormField(
              decoration: InputDecoration(
                  border: UnderlineInputBorder(), labelText: 'Name'),
            ),
            TextFormField(
              decoration: InputDecoration(
                  border: UnderlineInputBorder(), labelText: 'Phone'),
            ),
            TextButton(
              style: ButtonStyle(
                foregroundColor: MaterialStateProperty.all<Color>(Colors.blue),
              ),
              onPressed: () {},
              child: Text('Confirm'),
            )
          ],
        ),
        ) 
        );
  }
}

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    问题是由于列小部件造成的。

    关于栏目:

    它在垂直方向上占用最大空间,直到它被 SizedBox 或 Container 包裹起来,就像你的情况一样,并给出了一些特定的 height。

    所以,试着给你的Container 包裹在SingleScrollChildView 和一些height 让我们说height = 200.0 并试一试。

    希望这会奏效:)

    【讨论】:

    • 在更改为 ListView.builder 之前我确实工作得很好
    猜你喜欢
    • 2018-08-15
    • 2021-01-14
    • 2019-07-16
    • 1970-01-01
    • 2021-09-11
    • 2018-11-13
    • 1970-01-01
    • 2021-05-11
    相关资源
    最近更新 更多