Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
114 views
in Technique[技术] by (71.8m points)

android - What can i use to make an app like notes app where there is unexpected number of notes

I want to make a notes apo in flutter but i dont know that widget can i use to store the notes as the number of notes are unexpected

question from:https://stackoverflow.com/questions/65830708/what-can-i-use-to-make-an-app-like-notes-app-where-there-is-unexpected-number-of

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use ListView.builder or GridView.builder, just specify the number of items in the itemCount field.

Example using GridView.builder:

class MyHomePage extends StatelessWidget {
  final List<String> notes = ["Lorem", "Ipsum", "Dolor"];

  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      itemCount: notes.length,
      itemBuilder: (context, index) {
        return Padding(
          padding: EdgeInsets.all(8),
          child: Container(
            width: 200,
            height: 200,
            color: Colors.blue,
            child: Center(
              child: Text(notes[index]),
            ),
          ),
        );
      },
      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
      ),
    );
  }
}

Result: Example


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...