【问题标题】:Flutter - Error in PageView, parameters doesn´t existFlutter - PageView中的错误,参数不存在
【发布时间】:2019-05-21 07:29:07
【问题描述】:

我正在尝试在 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. 未定义命名参数 children。

那么,代码有什么问题?

问题更新

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

现在错误是“可听”是必需的。任何的想法?我认为是

【问题讨论】:

    标签: flutter pageviews


    【解决方案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)
            ],
          )
        );
      }
    }
    

    【讨论】:

    • 最后一个问题:当我向此页面发送参数时,显示警告:需要参数“listenable”。这是什么意思?
    • 请出示您的完整代码,我的意思是您在哪里收到警告
    猜你喜欢
    • 1970-01-01
    • 2021-01-08
    • 2021-11-13
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 2021-11-08
    相关资源
    最近更新 更多