抖动水平ListView BoxConstraints会强制设置无限宽度

时间:2020-07-09 13:31:57

标签: flutter dart flutter-layout

当前,我尝试在Card中显示水平的ListView Builder。 但是我总是收到一个错误消息,说“ BoxConstraints强制无限宽度。”

如果我构建具有垂直列表的列表视图,则一切正常。 当我更改为水平列表后,该列表就会消失。

我将附加一个屏幕截图,在其中标记水平列表视图应位于的区域。 Screnshoot of the current View

这是我对第二张卡的最后一次尝试: (我删除了第一张卡的代码,所以代码不会太长)

Expanded(
child: Container(
height: 250.0,
child: Card(
color: Color(_colors.getBackgroundColor()),
elevation: 10.0,
shadowColor: Colors.black54,
margin: EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(
color: Color(_colors.getLightMainColor()))),
     child: Padding(
         padding: const EdgeInsets.all(8.0),
            child: Container(
              width: 250.0,
               child: ListView.builder(
               scrollDirection: Axis.horizontal,
               itemCount: 1,
               itemBuilder: (context, index) {
               return ListTile(
               title: Text('Test'),
                  );
                 }),
               )),
              ),
             ),
   ),

1 个答案:

答案 0 :(得分:0)

我已经更新了您的代码,使其可以正常运行。

请记住,您不能水平 @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { private static final Logger log = LogManager.getLogger(); @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/**").authenticated() .and() .httpBasic(); http.csrf().disable(); } @Bean public UserDetailsService userDetailsService() { String username = "username"; String password = "password"; InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); String encodedPassword = passwordEncoder().encode(password); manager.createUser(User.withUsername(username).password(encodedPassword).roles("USER").build()); return manager; } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } }

让我知道您是否还想要其他东西

ListTile

这可能对您有帮助