孩子们总是从父亲那里继承尺寸

时间:2019-10-11 18:27:51

标签: flutter

对不起,我的英语不好。 来吧,今天我过得不好,希望您看到我错了,因为我找不到问题,我创建了一个slideTransition,它位于顶部,该幻灯片作为第二个孩子放在堆栈上,问题是SlideTransition内部的儿子,我将其设置为屏幕的大小,但是您的孙子出于某种原因总是继承slideTransition内部父级的大小,孙子是SizedBox,但我需要孙子或子孙拥有尺寸有限。我尝试了很多方法,但是无法创建特定大小的孙子。此示例是MVP,只需在简单的flutter模板上复制并执行即可。

Flutter api SizedBox document

import 'package:flutter/material.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: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: TestScreen(),
    );
  }
}


class TestScreen extends StatefulWidget {
  @override
  _TestScreenState createState() => _TestScreenState();
}

class _TestScreenState extends State<TestScreen> with SingleTickerProviderStateMixin {
  AnimationController animation;
  Animation<Offset> offset;
  Animation<double> curved;  
  @override
  void initState() {
    super.initState();
    animation = new AnimationController(vsync: this, duration: Duration(milliseconds: 150));
    curved = new CurvedAnimation(parent: animation, curve: Curves.easeIn);
    offset = Tween<Offset>(
      begin: const Offset(0, -1),
      end: Offset.zero,
    ).animate(curved);
  }
  @override
  void dispose() {
    super.dispose();
    animation.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final appbar = new AppBar(
      title: FlatButton(
        child: Text('OPEN'),
        onPressed: () {
            if(animation.isDismissed){
              animation.forward();
            }else{
              animation.reverse();
            }
          },
        ),
      centerTitle: true,
      elevation: 4.0,
      automaticallyImplyLeading: false,
    );
    final body = Container(color: Colors.red, child: Center(child: Text('Screen')));

    final slideCalendar = new Align(
      alignment: Alignment.topCenter,
      child: SlideTransition(
        position: offset,
        child: Container(
          width: MediaQuery.of(context).size.width,
          height: double.infinity,
          child: SizedBox(
            height: 100.0,
            width: 200.0,
            child: Container(color: Colors.pink,child: Text('test')),
          )    //listCalendar,
        )
      ),
    );
    return Scaffold(
      appBar: appbar,
      body: Stack(
        children: <Widget>[
          body,
          slideCalendar
        ],
      ),
    );
  }
}

0 个答案:

没有答案