Flutter-PageView中的错误,参数不存在

时间:2019-05-21 07:29:07

标签: flutter pageviews

我正在尝试在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)
        ],
      ),
    );
  }
}

出现多个错误:

  1. 未定义命名的参数控制器。
  2. 未定义命名参数scrollDirection。
  3. 未定义命名参数的子级。

那么,代码有什么问题?

问题更新

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)
      ],
    ));
  }
}

现在,错误为“可监听”。任何想法?我认为是

1 个答案:

答案 0 :(得分:1)

您无法命名课程PageView,请尝试以下操作:

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)
        ],
      )
    );
  }
}