Home php c# sql c c++ javascript python java go android git linux asp.net django .net node.js ios xcode cocoa iphone mysql tomcat mongodb bash objective-c scala visual-studio apache elasticsearch jar eclipse jquery ruby-on-rails ruby rubygems android-studio spring lua sqlite emacs ubuntu perl docker swift amazon-web-services svn html ajax xml java-ee maven intellij-idea rvm macos unix css ipad postgresql css3 json windows-server vue.js typescript oracle hibernate internet-explorer github tensorflow laravel symfony redis html5 google-app-engine nginx firefox sqlalchemy lucene erlang flask vim solr webview facebook zend-framework virtualenv nosql ide twitter safari flutter bundle phonegap centos Register | Login | Edit Tags | New Questions | 繁体 | 简体


3 questions online user: 33

0
votes
answers
6 views
+10

顫動組列表與分隔符

1

我正在尋找一些指導來創建分隔符的列表視圖。例如,我想從按日期分組的數據庫中獲取消息,並按照日期將消息與某些圖形或行等分開,然後在分隔符下面顯示消息。試試這個撲動,任何指導或推動正確的方向將不勝感激。顫動組列表與分隔符

沙发
0
3

我的設計的醜陋道歉,但只是爲了告訴你,你幾乎可以建立自己的設計,你的願望,這是一個簡單的例子:

enter image description here

import "package:flutter/material.dart"; 
import 'package:meta/meta.dart'; 

class Test extends StatefulWidget { 
    @override 
    _TestState createState() => new _TestState(); 
} 

class _TestState extends State<Test> { 
    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     appBar: new AppBar(
     title: new Text("Test"), 
    ), 
     body: new ListView.builder(
     // itemCount: myData.lenght(), 
      itemCount: 20, 
      itemBuilder: (BuildContext context, int index) { 
      //sort my data by timestamp before building 
      return new CustomWidget(date: "Convert my time stamp to date", 
       content: "My Awesome Content", 
       trailingIconOne: new Icon(Icons.share, color: Colors.blueAccent,), 
       trailingIconTwo: new Icon(
       Icons.favorite, color: Colors.redAccent,),); 
      }), 
    ); 
    } 
} 

class CustomWidget extends StatelessWidget { 
    String date; 
    String content; 

    Icon trailingIconOne; 

    Icon trailingIconTwo; 

    CustomWidget(
     {@required this.date, @required this.content, @required this.trailingIconOne, @required this.trailingIconTwo}); 

    @override 
    Widget build(BuildContext context) { 
    return new Container(
     decoration: new BoxDecoration(
      border: new Border.all(color: Colors.grey[500]) 
    ), 
     child: new Column(
     children: <Widget>[ 
      new Container (child: new Text(date), color: Colors.yellow[200],), 
      new Container(height: 15.0,), 
      new Text(content), 
      new Row(
      mainAxisAlignment: MainAxisAlignment.end, 
      children: <Widget>[ 
       new IconButton(icon: trailingIconOne, onPressed:() {}), 
       new Container(width: 10.0,), 
       new IconButton(icon: trailingIconTwo, onPressed:() {}) 
      ], 
     ) 
     ], 
    ), 
    ); 
    } 
} 

對於更好的設計,你可以擺脫邊框並使用Divider來代替:

return new Container(
     child: new Column(
     children: <Widget>[ 
      new Column (children: <Widget>[ 
      new Container (child: new Text(date), color: Colors.yellow[200],), 
      new Container(height: 15.0,), 
      new Text(content), 
      new Row(
       mainAxisAlignment: MainAxisAlignment.end, 
       children: <Widget>[ 
       new IconButton(icon: trailingIconOne, onPressed:() {}), 
       new Container(width: 10.0,), 
       new IconButton(icon: trailingIconTwo, onPressed:() {}), 
      ],), 

       new Divider(height: 15.0,color: Colors.red,), 
      ], 
     ) 
     ], 
    ), 

而且在我看來,更好的視覺解決方案是使用一個Card代替Container

return new Card(
     child: new Column(
     children: <Widget>[ 
      new Column (children: <Widget>[ 
      new Container (child: new Text(date), color: Colors.yellow[200],), 
      new Container(height: 15.0,), 
      new Text(content), 
      new Row(
       mainAxisAlignment: MainAxisAlignment.end, 
       children: <Widget>[ 
       new IconButton(icon: trailingIconOne, onPressed:() {}), 
       new Container(width: 10.0,), 
       new IconButton(icon: trailingIconTwo, onPressed:() {}), 
      ],), 

      // new Divider(height: 15.0,color: Colors.red,), 
      ], 
     ) 
     ], 
    ), 
    ); 
+1

謝謝,我認爲是足夠讓我從正確的方向開始。如果我一路卡住,我會發佈一個新項目。 – Robert

+0

不要那樣做!使用'new Divider()'而不是灰色邊框...... – Darky

+0

無論如何,我並不打算展示一個偉大的設計,是的Divider更好,但只是在這個特定的佈局中,它需要調整才能產生效果。我在最後添加了更改,如果我們使用Card而不是Container作爲父級,那麼這可能會是一個更好看的設計,但此示例僅用於表明您可以自定義自己的小部件。 – aziza

板凳
0
0

雖然這可能並不適用於您的情況,一個簡單的方法來分隔添加到ListView是使用ListView.divideTiles

// Adapted from https://flutter.io/flutter-for-android/#listviews--adapters 

import 'package:flutter/material.dart'; 

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

class MyApp extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new MaterialApp(
     title: 'Flutter Demo', 
     theme: new ThemeData(
     primarySwatch: Colors.blue, 
    ), 
     home: new ListExamplePage(), 
    ); 
    } 
} 

class ListExamplePage extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    // https://docs.flutter.io/flutter/material/ListTile/divideTiles.html 
    var dividedWidgetList = ListTile.divideTiles(
     context: context, 
     tiles: _getListData(), 
     color: Colors.black).toList(); 

    return new Scaffold(
     appBar: new AppBar(
     title: new Text('List Example'), 
    ), 
     body: new ListView(children: dividedWidgetList) 
    ); 
    } 

    _getListData() { 
    List<Widget> widgets = []; 
    for (int i=0; i<100; i++) { 
     widgets.add(
     new Padding(
      padding: new EdgeInsets.all(10.0), 
      child: new Text('Row $i')) 
    ); 
    } 
    return widgets; 
    } 
} 

編輯:

對於動態生成列表,ListTile.divideTiles不是正確的選擇。在其中列表項目建成階段添加分隔可能是最好的一段路要走:

import 'package:flutter/material.dart'; 

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

class MyApp extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new MaterialApp(
     title: 'Flutter Demo', 
     theme: new ThemeData(
     primarySwatch: Colors.blue, 
    ), 
     home: new ListExamplePage(), 
    ); 
    } 
} 

class ListExamplePage extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     appBar: new AppBar(
      title: new Text('List Example'), 
     ), 
     body: new ListView.builder(
      itemBuilder: (BuildContext context, int position) => 
       // Try using either _getRowWithDivider or _getRowWithBoxDecoration 
       // for two different ways of rendering a divider 
       _getRowWithDivider(position), 
     )); 
    } 

    /// Returns the widget at position i in the list, separated using a divider 
    Widget _getRowWithDivider(int i) { 
    var children = <Widget>[ 
     new Padding(padding: new EdgeInsets.all(10.0), child: new Text('Row $i')), 
     new Divider(height: 5.0), 
    ]; 

    return new Column(
     crossAxisAlignment: CrossAxisAlignment.start, 
     children: children, 
    ); 
    } 

// Returns the widget at position i in the list, separated using a BoxDecoration 
    Widget _getRowWithBoxDecoration(int i) { 
    return new Container(
     decoration: new BoxDecoration(
      border: 
       new Border(bottom: new BorderSide(color: Colors.grey[100]))), 
     child: new Padding(
      padding: new EdgeInsets.all(10.0), child: new Text('Row $i'))); 
    } 
} 
+0

這看起來很有希望,如果我通過http調用得到我的消息列表,那麼我將它放在一個列表中,現在我使用listview。生成器併爲每個項目應用一個小部件,但是現在我需要一個按日期分割的日期,每個日期可以是1或多個。我現在正在嘗試做一個列表視圖,其中包含消息列表視圖,但是與大小錯誤對等。您的解決方案看起來更直接,接受日期所需的分隔符而不是每個分隔符。任何建議都會很棒。 – Robert

+0

對於動態列表,不幸的是ListTile.divideTiles不會爲你工作。我建議使用aziza的建議,並在每行構建小部件時插入分隔符(或BoxDecoration)。我將更新一個不同的代碼片段來演示。 –

地板
0
0

簡單地把ListItemContainer,並添加裝飾:

@override 
    Widget build(BuildContext context) { 
    return new Container(
     child: new ListTile(
      title: new Text('I have border') 
     ), 
     decoration: 
      new BoxDecoration(
       border: new Border(
        bottom: new BorderSide() 
       ) 
      ) 
     ); 
    } 
0
votes
answers
5 views
+10

Flutter應用程序中顯示圖像和用戶反應的準確時間

1

我必須創建一個心理反應時間測試應用程序。爲此,我必須準確地控制圖像何時可見,並準確測量圖像可見性開始和反應開始(例如點擊事件)之間的延遲。 我該如何在Flutter中實現?具體而言,在同一地點顯示和隱藏多個不同圖像的最有效方式是什麼?我如何才能準確知道點擊事件的發生與真實和完全可見性的發生相關,並考慮到幀設備的速率?是否有辦法對這個過程進行低級控制。通常Flutter似乎暴露了高級別的API。Flutter應用程序中顯示圖像和用戶反應的準確時間

沙发
0
3

我已經做出了嘗試是有可能正是你在找什麼,我的邏輯如下:

  1. 添加監聽到的圖像呈現。
  2. 使用Stopwatch類,我通知我的對象在圖像顯示後開始計時。
  3. 當點擊正確答案時,我停止Stopwatch停止計數。
  4. 保存我目前的分數,並繼續下一個問題。

注:

  • 在這個例子中,爲簡單起見,我沒有爲哪個答案是正確的,這是不是一個帳戶。
  • 我創建了一個新的StatelessWidget來保存每個問題,使用PageView.builder也可能是一個很好的用法。

簡單的例子:

enter image description here

import 'dart:async'; 

import 'package:flutter/material.dart'; 

int score = 0; 

class TimeTest extends StatefulWidget { 
    Widget nextQuestionWidget; //to navigate 
    String question; 
    NetworkImage questionImage; 
    List<String> answers; 

    TimeTest(
     {this.questionImage, this.question, this.answers, this.nextQuestionWidget }); 

    @override 
    _TimeTestState createState() => new _TimeTestState(); 
} 

class _TimeTestState extends State<TimeTest> { 
    final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); 
    bool _loading = true; 
    Stopwatch timer = new Stopwatch(); 

    @override 
    void initState() { 
    widget.questionImage.resolve(new ImageConfiguration()).addListener((_, __) { 
     if (mounted) { 
     setState(() { 
      _loading = false; 
     }); 
     timer.start(); 
     } 
    }); 
    } 

    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     key: _scaffoldKey, 
     appBar: new AppBar(title: new Text("Time Test"),), 
     body: new Container(
     alignment: FractionalOffset.center, 
     margin: const EdgeInsets.symmetric(vertical: 15.0), 
     child: new Column(
      children: <Widget>[ 
      new Text(widget.question), 
      new Divider(height: 15.0, color: Colors.blueAccent,), 
      new CircleAvatar(backgroundImage: widget.questionImage, 
       backgroundColor: Colors.transparent,), 
      new Container(height: 15.0,), 
      new Column(
       children: new List.generate(widget.answers.length, (int index) { 
       return new FlatButton(
        onPressed:() { 
        ///TODO 
        ///add conditions for correct or incorrect answers 
        ///and some manipulation on the score 
        timer.stop(); 
        score = score + timer.elapsedMilliseconds; 
        print(score); 
        _scaffoldKey.currentState.showSnackBar(new SnackBar(
         content: new Text(
          "Your answered this question in ${timer 
           .elapsedMilliseconds}ms"))); 

        ///Hold on before moving to the next question 
        new Future.delayed(const Duration(seconds: 3),() { 
         Navigator.of(context).push(new MaterialPageRoute(
          builder: (_) => widget.nextQuestionWidget)); 
        }); 
        }, child: new Text(widget.answers[index]),); 
       }), 
      ) 
      ], 

     ),), 
    ); 
    } 
} 


class QuestionOne extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new TimeTest(question: "Which animal is in this photo?", 
     questionImage: new NetworkImage(
      "http://cliparting.com/wp-content/uploads/2016/09/Tiger-free-to-use-clipart.png"), 
     answers: ["Lion", "Tiger", "Cheetah"], 
     nextQuestionWidget: new QuestionTwo(),); 
    } 
} 

class QuestionTwo extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new TimeTest(question: "Which bird is in this photo?", 
     questionImage: new NetworkImage(
      "http://www.clker.com/cliparts/P/q/7/9/j/q/eagle-hi.png"), 
     answers: ["Hawk", "Eagle", "Falcon"], 
     nextQuestionWidget: new ResultPage(),); 
    } 
} 

class ResultPage extends StatelessWidget { 
    @override 
    Widget build(BuildContext context) { 
    return new Scaffold(
     appBar: new AppBar(title: new Text("Result"),), 
     body: new Center(
     child: new Text("CONGRATULATIONS! Your score is $score milliseconds"),), 
    ); 
    } 
} 
void main() { 
    runApp(new MaterialApp(home: new QuestionOne())); 
} 
+0

Grrrrrreat !!!!! – Michael

+0

此解決方案在屏幕上推送新路線。是不是像大量路線的內存泄漏?我寧願替換現有的圖像我如何存檔? – Michael

+0

我不想使用pushReplacement,因爲它取代了整個小部件。是否可以簡單地只交換圖像並在顯示時準確通知? – Michael

0
votes
answers
4 views
+10

我可以在Android上啓動聯繫人應用程序,並實際獲得選定的聯繫人手機號碼撲動?

0

有沒有辦法啓動聯繫人應用程序,並獲取任何撲翼應用程序後選擇的聯繫人號碼。我可以在Android上啓動聯繫人應用程序,並實際獲得選定的聯繫人手機號碼撲動?

我已經成功地只能使用urlurl_launcher包,但無法找到一個方法來返回選定聯繫人回到應用程序啓動,

請可有人告訴我,我們如何能在撲手機做到這一點應用。

非常感謝, 馬希

+0

請記住,如果您願意,可以進行android/IOS調用。 – Darky

沙发
0
1

這是不可能的url_launcher包。已有一個contact_picker package可用於撲動,允許您選擇一個聯繫人。

希望有幫助!

+0

謝謝@Hemanth Raj你是一個明星隊友,我會嘗試這個包,讓你知道如果這個作品非常感謝你。 – Mahi

+0

啊,沒關係!只要接受答案,如果它有幫助。 –