0

在此处输入图像描述我必须在颤振中使用时钟向导,如果直接插入正文中,它可以正常工作,但我想在列中使用它,但它显示错误。我试图将它用作另一个有状态的小部件并在列的子级内部调用,但仍然出现错误。任何帮助..???

import 'package:analog_clock_example/demo.dart';
import 'package:flutter/material.dart';

import 'package:analog_clock/analog_clock.dart';

void main() => runApp(MyApp());
//void main() => runDemo();

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) => MaterialApp(
          home: Scaffold(
        body: AnalogClock(),
      ));
}
4

1 回答 1

1

我认为它会给你一个错误,因为你不能设置它的约束。
试试这样的,

import 'package:analog_clock_example/demo.dart';
import 'package:flutter/material.dart';

import 'package:analog_clock/analog_clock.dart';

void main() => runApp(MyApp()); 

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) => MaterialApp(
          home: Scaffold(
          body: Column(
               children: [
                  Container(
                    height: 300.0,       // Missing Constraints
                    width: 300.0,
                    child: AnalogClock(),
                 ),
             ],
          ),
      ),
    );
}

确保您停止并再次运行它而不是执行Hot Reload. 希望有效!

于 2020-08-29T15:26:52.740 回答