我正在尝试在flutter 1.5中创建一个简单的PageView。代码类似于:

import 'package:flutter/material.dart';
import 'package:datameter/screens/configuration/form/partials/form_page.dart';

class PageView extends AnimatedWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: PageController(
          initialPage: 1,
          viewportFraction: 0.8,
        ),
        scrollDirection: Axis.vertical,
        children: [
          FormPageScreen,
          Container(
              margin: EdgeInsets.symmetric(
                horizontal: 10.0,
              ),
              color: Colors.purpleAccent),
          Container(
              margin: EdgeInsets.symmetric(
                horizontal: 10.0,
              ),
              color: Colors.greenAccent)
        ],
      ),
    );
  }
}

出现多个错误:
未定义命名参数控制器。
未定义命名参数ScrollDirection。
未定义命名参数子级。
那么,代码有什么问题?
问题更新
import 'package:flutter/material.dart';
import 'package:datameter/screens/configuration/form/partials/slider/partials/form_page.dart';

class PageViewPage extends AnimatedWidget {
  final double latitude;
  final double longitude;

  final String aliasValue;
  final String datameterValue;
  final String contadorModelValue;
  final String contadorFabricanteValue;
  final String contadorValue;
  final String instalation;
  final String otherFabricante;
  final String otherModelo;
  final List arrayDatos;

  PageViewPage(
      {Key key,
      this.instalation,
      this.latitude,
      this.longitude,
      this.aliasValue,
      this.datameterValue,
      this.contadorModelValue,
      this.contadorFabricanteValue,
      this.contadorValue,
      this.otherFabricante,
      this.arrayDatos,
      this.otherModelo})
      : super(key: key); //HERE A WARNING APPEAR: LISTENABLE IS REQUIRED

  final controller = PageController(
    initialPage: 1,
    viewportFraction: 0.8,
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: PageView(
      controller: controller,
      scrollDirection: Axis.vertical,
      children: <Widget>[
        FormPageScreen(),
        Container(color: Colors.red),
        Container(color: Colors.blue)
      ],
    ));
  }
}

现在需要“可侦听”错误。知道吗?我想是的

最佳答案

无法命名类,请尝试以下操作:

class PageViewAnimated extends AnimatedWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: PageController(
          initialPage: 1,
          viewportFraction: 0.8,
        ),
        scrollDirection: Axis.vertical,
        children: <Widget>[
          FormPageScreen(),
          Container(
              margin: EdgeInsets.symmetric(
                horizontal: 10.0,
              ),
              color: Colors.purpleAccent),
          Container(
              margin: EdgeInsets.symmetric(
                horizontal: 10.0,
              ),
              color: Colors.greenAccent)
        ],
      )
    );
  }
}

关于flutter - Flutter - PageView中的错误,参数不存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56233257/

10-16 07:51