使文本变得扑朔迷离

时间:2019-08-06 09:30:28

标签: flutter

好,所以我有一个复杂的问题 所以我在这个列表中有一个复选框和一些文本,我希望我可以添加一个图像来欺骗它以思考其文本问题是,每当我添加一些文本时,图像就会随之添加I

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';
import 'package:image_picker/image_picker.dart';
void main() {
  runApp(new MyApp(
    title: new Text("My App"),
    someText: new Text("Some Text..."),
  ));
}
class MyApp extends StatefulWidget {
  MyApp({this.title, this.someText});

  final Widget title, someText;

  @override

_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  File _image;

  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);
    setState(() {
      _image = image;
    });
  }

  TextEditingController eCtrl = new TextEditingController();
  bool showDialog = false;
  List<String> textlist = [];
  List<bool> textChkBox = [];

  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: widget.title,
          actions: <Widget>[
            new IconButton(
                icon: new Icon(Icons.add_comment),
                onPressed: () {
                  setState(() {
                    showDialog = true;
                  });
                }),
            ),
            new FloatingActionButton(
              onPressed:  getImage,
              tooltip: 'pick Image',
              child: new Icon(Icons.camera),
            ),
          ],
        ),
        body: new Column(
          children: <Widget>[
            showDialog == true
                ? new AlertDialog(
              title: new Text("Alert Dialog"),
              content: new TextField(
                controller: eCtrl,
                decoration: new InputDecoration.collapsed(hintText: "ADD XYZ"),
                maxLines: 6,
                onSubmitted: (String text) {},
              ),
              actions: <Widget>[
                new FlatButton(
                    onPressed: () {
                      setState(() {
                        showDialog = false;
                        textlist.add(eCtrl.text);
                        textChkBox.add(false);
                        eCtrl.clear();
                      });
                    },
                    child: new Text("OK"))
              ],
            ) : new Text(""),
            new Flexible(
                child: new ListView.builder(
                    itemCount: textlist.length,
                      itemBuilder: (BuildContext ctxt, int index) {
                        return new Column(children: <Widget>[
                          new Checkbox(
                             value: textChkBox[index],
                             onChanged: (bool newValue) {
                               textChkBox[index] = newValue;
                               setState(() {});
                             },
                          ),
                          new Text(textlist[index]),
                          new Card(
                            child: _image == null ? new Text("-")
                            : new Image.file(_image),
                          ),
                        ]
                      );
                    }
                )
            )
          ],
        ),
      ),
    );
  }
}

如您所见,它同时显示复选框,文本和图像

0 个答案:

没有答案