2017-08-30 81 views
4

我正在使用TextField但鍵盤提高FloatingActionButton。我想知道鍵盤是否可以不提高FloatingActionButton?根據下面的gif,在下面的代碼中,我以兩種不同的方式放置了兩個FloatingActionButton,但是在兩個鍵盤都向上的情況下,由於FAB與TextField位於同一行,因此妨礙了字段填充。顫振 - 鍵盤在屏幕上浮動FloatingActionButton

有什麼辦法解決這個問題嗎?

enter image description here

import 'package:flutter/material.dart'; 
import 'dart:ui' as ui; 

void main() { 
    runApp(new MyApp()); 
} 

class MyApp extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new MaterialApp(  
     home: new MyHomePage(), 
    ); 
    } 
} 

class MyHomePage extends StatefulWidget { 
    @override 
    _MyHomePageState createState() => new _MyHomePageState(); 
} 

class _MyHomePageState extends State<MyHomePage> { 
    @override 
    Widget build(BuildContext context) { 
    final ui.Size logicalSize = MediaQuery.of(context).size; 
    final double _width = logicalSize.width; 
    return new Scaffold(
     appBar: new AppBar(backgroundColor: new Color(0xFF26C6DA)),   
     body: new Stack(
     children: <Widget>[ 
      new ListView(
      children: <Widget>[ 
       new TextField(
       decoration: const InputDecoration(
        labelText: "Description", 
       ), 
       style: Theme.of(context).textTheme.title, 
      ), 
       new TextField(
       decoration: const InputDecoration(
        labelText: "Description", 
       ), 
       style: Theme.of(context).textTheme.title, 
      ), 
       new TextField(
       decoration: const InputDecoration(
        labelText: "Description", 
       ), 
       style: Theme.of(context).textTheme.title, 
      ), 
      ], 
     ), 
      new Positioned(
      bottom: 16.0, 
      left: (_width/2) - 28, 
      child: new FloatingActionButton(
       backgroundColor: new Color(0xFFE57373), 
       child: new Icon(Icons.check), 
       onPressed:(){} 
      ),    
     ) 
     ],   
    ), 
     floatingActionButton: new FloatingActionButton(
     backgroundColor: new Color(0xFFE57373), 
     child: new Icon(Icons.check), 
    ), 
    ); 
    } 
} 

回答

3

它看起來像你正在設計一個全屏幕的對話框。

浮動操作按鈕表示應用程序中的主要操作,如創建新項目。這不是您用來確認更改並關閉包含文本字段列表的全屏對話框。

不是使用FloatingActionButton,我會一個在actions插槽建議用FlatButtonAppBar,就像這個Material design example

save

你可以看到如何建立一個全的例子Flutter中的屏幕對話框在Gallery source code中。

+0

謝謝,我理解Material Design的概念,但爲了探索Flutter,我意識到Stack和Positioned將會一直上升。爲了解決問題,我使用列重建了代碼,並且它僅在將MainAxisAlignment:MainAxisAlignment.spaceBetween的SingleChildScrollView屬性放置時才起作用,它將停止工作。所以我打開另一個問題https://stackoverflow.com/questions/45982176/flutter-singlechildscrollview-interfering-in-columns – rafaelcb21