preloaded_images 1.0.0 copy "preloaded_images: ^1.0.0" to clipboard
preloaded_images: ^1.0.0 copied to clipboard

outdated

A new flutter plugin to fetch latest 'X' images from mobile storage. It returns list of asset url's and works both on IOS and Android.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:preloaded_images/preloaded_images.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List allImage = List();
  bool loading = true;

  @override
  void initState() {
    super.initState();
    getImages();
  }

  // Call this function at your app start or at any place
  // to fetch the latest images from your phone storage.
  getImages() async {
    allImage = [];
    List allImageTemp = await PreloadedImages.getImages(count: 5);
    allImage.addAll(allImageTemp);
    print(allImage);
    setState(() {
      loading = false;
    });
  }

  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        backgroundColor: Colors.white,
        body: Center(
          child: loading
              ? CircularProgressIndicator()
              : allImage.length == 0
                  ? Text(
                      "Either permission was declined or no images in storage",
                      maxLines: null,
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Colors.black,
                        fontSize: 25,
                      ),
                    )
                  : GridView.builder(
                      shrinkWrap: true,
                      padding: EdgeInsets.all(20),
                      gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 2,
                        childAspectRatio: 1.0,
                        crossAxisSpacing: 5,
                      ),
                      itemBuilder: (context, index) {
                        return Container(
                          margin: EdgeInsets.only(bottom: 5),
                          decoration: BoxDecoration(
                            border: Border.all(color: Colors.red),
                            borderRadius: BorderRadius.circular(5),
                            color: Colors.grey[200],
                          ),
                          child: ClipRRect(
                            borderRadius: BorderRadius.circular(5),
                            child: Image.asset(
                              "${allImage[index]}",
                              fit: BoxFit.cover,
                              height: 100,
                              // width: 100,
                            ),
                          ),
                        );
                      },
                      itemCount: allImage.length,
                    ),
        ),
      ),
    );
  }
}
9
likes
0
pub points
0%
popularity

Publisher

verified publishersuresh-konakanchi.in

A new flutter plugin to fetch latest 'X' images from mobile storage. It returns list of asset url's and works both on IOS and Android.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on preloaded_images