Flutter - PageView 错误,参数不存在
Flutter - Error in PageView, parameters doesn´t exist
我正在尝试在 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。
- 未定义命名参数 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)
],
));
}
}
现在的错误是 "listenable" 是必需的。任何的想法?我认为是
您无法命名您的 class 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)
],
)
);
}
}
我正在尝试在 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。
- 未定义命名参数 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)
],
));
}
}
现在的错误是 "listenable" 是必需的。任何的想法?我认为是
您无法命名您的 class 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)
],
)
);
}
}