2017-12-31 366 views

答えて

4

PageView(physics:new NeverScrollableScrollPhysics()) 
0

私はこれを次のように理解しようとしました。誰かがより良い解決策を持っている場合は、私たちと共有してください。

はボタンがPageViewの次の項目に移動してください:

あなたPageViewPageControllerを追加し、ユーザーがボタンを押したときの方法animateToまたはjumpToは、目的の項目に移動するには。現在のビューの幅全体がオフセットであるようにして、次のアイテムへの移行が正常に行われるようにしました。

onPressed:() { 
     c.animateTo(MediaQuery 
      .of(context) 
      .size 
      .width, duration: new Duration(seconds: 1), 
      curve: Curves.easeIn); 
     } 

行動をスワイプデフォルトを無効にします。私はすべてのユーザーとの対話を無視するIgnorePointer内の私のPageViewを包むことだった

、私は本当にこのソリューションを好きではない、それはで正常に動作することができますしかし、この例では、他の状況では、現在表示されているページ内の1つのウィジェットとユーザーがやり取りすることが必要な場合があります。

これは私のサンプルコードです:このソリューションで

enter image description here

class FirstPage extends StatefulWidget { 
    @override 
    _FirstPageState createState() => new _FirstPageState(); 
} 

class _FirstPageState extends State<FirstPage> { 
    ScrollController c; 

    @override 
    void initState() { 
    super.initState(); 
    c = new PageController(); 
    } 

    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     floatingActionButton: new Row(
     mainAxisAlignment: MainAxisAlignment.end, 
     crossAxisAlignment: CrossAxisAlignment.end, 

     children: <Widget>[ 
      new FloatingActionButton(
       child: new Icon(Icons.navigate_before), onPressed:() { 
      //c.animateTo(MediaQuery.of(context).size.width, duration: new Duration(seconds: 1), curve: Curves.easeIn); 
      c.jumpTo(0.0); 
      }), 
      new Container(width: 15.0,), 
      new FloatingActionButton(
       child: new Icon(Icons.navigate_next), onPressed:() { 
      c.animateTo(MediaQuery 
       .of(context) 
       .size 
       .width, duration: new Duration(seconds: 1), 
       curve: Curves.easeIn); 
      }), 
     ],), 
     appBar: new AppBar(title: new Text("First Page")), 
     body: new IgnorePointer(child: new PageView(
     controller: c, 
     children: <Widget>[ 
      new Column (
       children: <Widget>[new Container (child: new Text("First Item")) 
       ]), 
      new Container (child: new Text("Second Item")), 
     ], 
    ),), 
    ); 
    } 
} 

任意の提案や修正は歓迎されています。あなたが設定することができますスワイプ無効にするには

関連する問題