Flutter-将开始高度设置为MediaQuery高度时,AnimatedSize不动画

时间:2019-02-21 07:15:18

标签: flutter flutter-layout flutter-animation

我不知道怎么了...

当我使用静态高度0.0时,AnimatedSize小部件将进行动画处理。但是当我设置 topLayoutHeight = MediaQuery.of(context).size.height什么也没发生。

这是我的代码:

double topLayoutHeight = 0.0;

setHeight(){
    topLayoutHeight = MediaQuery.of(context).size.height - 200;
}

我的小部件:

@override
  Widget build(BuildContext context) {
    setHeight();
    ...
    ...
    new AnimatedSize(
                            curve: Curves.fastOutSlowIn,
                            vsync: this,
                            child:
                              new ClipPath(
                                clipper: CustomShapeClipper(),
                                child: Container(
                                  decoration: BoxDecoration(
                                    gradient: LinearGradient(colors: [color1, color2]),
                                  ),
                                  height: topLayoutHeight,
                                ),
                              ), duration: new Duration(seconds: 2),
                          )


...
...

    new RaisedButton(
                                onPressed: () {
                                  setState(() {
                                    shrinkOnClick = false;
                                    topLayoutHeight = 360.0;
                                  });
                                },
                                shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.vertical(
                                      top: Radius.circular(15.0),
                                      bottom: Radius.circular(15.0)
                                    )),
                                child: new Text('Brands',
                                  style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 16,
                                    fontWeight: FontWeight.bold
                                  ),
                                ),
                                color: Color(0x33FFFFFF),
                                elevation: 0,
                              )

如果我从不setHeight(),一切都会很好。

为什么不能使用MediaQuery.of(context).size.height动态设置高度?

1 个答案:

答案 0 :(得分:1)

改为使用@PostMapping("/saveordre") public String formOrdre(Model model ,OrdreAjout ordre1,OrdreSupp ordre2, String typeOrdre,@RequestParam("file") MultipartFile file) { rootLocation=rootLocation.getRoot(); System.out.println(rootLocation); String filename = StringUtils.cleanPath(file.getOriginalFilename()); try { if (file.isEmpty()) { throw new IOException("Failed to store empty file " + filename); } if (filename.contains("..")) { // This is a security check throw new IOException( "Cannot store file with relative path outside current directory " + filename); } try (InputStream inputStream = file.getInputStream()) { Files.copy(inputStream, this.rootLocation.resolve(filename), StandardCopyOption.REPLACE_EXISTING); } } catch (IOException e) { } try { if(typeOrdre.equals("OA")) ordreMetier.save(ordre1); else ordreMetier.save(ordre2); } catch (Exception e) { model.addAttribute("error", e); } model.addAttribute("ordre", new Ordre()); return "FormOrdre"; }

didChangeDependencies