Snippets Collections
List<String> feed = List();

feed.add("AAAA");
feed.add("BBBB");
feed.add("CCCC");

ListView.builder(
  itemCount: feed.length,
  itemBuilder: (context, index) {
    return ListTile(title: feed[feed.length - 1 -index]);
  },
);
import 'dart:math';

void main() {
  print(getRandomString(5));  // 5GKjb
  print(getRandomString(10)); // LZrJOTBNGA
  print(getRandomString(15)); // PqokAO1BQBHyJVK
}

const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _rnd = Random();

String getRandomString(int length) => String.fromCharCodes(Iterable.generate(
    length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
import 'dart:io';
import 'package:exif/exif.dart';
import 'package:image/image.dart' as img;

Future<File> fixExifRotation(String imagePath) async {
    final originalFile = File(imagePath);
    List<int> imageBytes = await originalFile.readAsBytes();

    final originalImage = img.decodeImage(imageBytes);

    final height = originalImage.height;
    final width = originalImage.width;

    // Let's check for the image size
    // This will be true also for upside-down photos but it's ok for me
    if (height >= width) {
      // I'm interested in portrait photos so
      // I'll just return here
      return originalFile;
    }

    // We'll use the exif package to read exif data
    // This is map of several exif properties
    // Let's check 'Image Orientation'
    final exifData = await readExifFromBytes(imageBytes);

    img.Image fixedImage;

    if (height < width) {
      logger.logInfo('Rotating image necessary');
      // rotate
      if (exifData['Image Orientation'].printable.contains('Horizontal')) {
        fixedImage = img.copyRotate(originalImage, 90);
      } else if (exifData['Image Orientation'].printable.contains('180')) {
        fixedImage = img.copyRotate(originalImage, -90);
      } else if (exifData['Image Orientation'].printable.contains('CCW')) {
        fixedImage = img.copyRotate(originalImage, 180);
      } else {
        fixedImage = img.copyRotate(originalImage, 0);
      }
    }

    // Here you can select whether you'd like to save it as png
    // or jpg with some compression
    // I choose jpg with 100% quality
    final fixedFile =
        await originalFile.writeAsBytes(img.encodeJpg(fixedImage));

    return fixedFile;
  }
Color color = new Color(0x12345678);
String colorString = color.toString(); // Color(0x12345678)
String valueString = colorString.split('(0x')[1].split(')')[0]; // kind of hacky..
int value = int.parse(valueString, radix: 16);
Color otherColor = new Color(value);
//I think your understanding of Promises and async/await is not correct.
//When you make a function async, the await keyword before a promise make sure
//that code execution will pause until the promise fulfilled or rejected. 
//Your code can be simplified:

var currentPromise;

async function asyncFunc(promise){
    // Do some code here
    return await promise;
}

function anotherFunction(){
    asyncFunc(currentPromise);
}
//When we are calling return await promise, the execution engine waits in a
//non-blocking way until the promise fulfilled or rejected, and then it returns 
//the output to the anotherFunction function.
const placeholderServices = [
  PlaceholderService(
    name: 'Place Kitten',
    description:
        'Use the Internet first-class citizens as placeholders for your Website.',
    url: 'https://placekitten.com',
    pictureUrl: 'https://placekitten.com/1024/768',
    tags: ['Fun', 'Grayscale'],
  ),
  PlaceholderService(
    name: 'Fill Murray',
    description:
        'Iconic pictures of Bill Murray. Also by the same author: PlaceCage and Steven SeGallery.',
    url: 'http://www.fillmurray.com',
    pictureUrl: 'http://www.fillmurray.com/1200/900',
    tags: ['Fun', 'Grayscale', 'Open-source'],
  ),
  PlaceholderService(
    name: 'PlaceIMG',
    description:
        'Returns stock photos for a given theme, like "Architecture", "Tech" or "People". Also support sepia filter.',
    url: 'http://placeimg.com',
    pictureUrl: 'http://placeimg.com/1200/900/arch',
    tags: ['Stock photo', 'Grayscale', 'Sepia', 'Themes'],
  ),
  PlaceholderService(
    name: 'Bacon Mockup',
    description:
        'Bacon images, but not only. Also on display: briskets, pulled pork, drumsticks, ribs, etc.',
    url: 'https://baconmockup.com',
    pictureUrl: 'https://baconmockup.com/1200/900',
    tags: ['Fun'],
  ),
  PlaceholderService(
    name: 'Placemat',
    description:
        'Stock images categorized in 3 themes: "People", "Places" and "Things. Various options of customization: text, overlay, random seed.',
    url: 'https://placem.at',
    pictureUrl: 'https://placem.at/things?w=1200&h=900',
    tags: ['Stock photo', 'Text', 'Themes', 'Overlay'],
  ),
  PlaceholderService(
    name: 'Dynamic Dummy Image Generator',
    description:
        'More developer-oriented, this service returns plain mono-color images. Lots of handy options including shortcuts for different screen or ads resolutions.',
    url: 'https://dummyimage.com',
    pictureUrl: 'https://dummyimage.com/1200x900/bada55/ffffff',
    tags: ['Technical', 'Text', 'Formats'],
  ),
  PlaceholderService(
    name: 'lorempixel',
    description:
        'Another stock photo placeholder service. Note the "Abstract" category because sometimes you just want your image to represent nothing.',
    url: 'http://lorempixel.com',
    pictureUrl: 'http://lorempixel.com/1200/900/sports',
    tags: ['Stock photo', 'Text', 'Grayscale', 'Themes'],
  ),
];
Widget _signInButton() {




   return OutlineButton(


     splashColor: Colors.grey,


     onPressed: () {},


     shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),


     highlightElevation: 0,


     borderSide: BorderSide(color: Colors.grey),


     child: Padding(


       padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),


       child: Row(


         mainAxisSize: MainAxisSize.min,


         mainAxisAlignment: MainAxisAlignment.center,


         children: <Widget>[


           Image(image: AssetImage("assets/google_logo.png"), height: 35.0),


           Padding(


             padding: const EdgeInsets.only(left: 10),


             child: Text(


               'Sign in with Google',


               style: TextStyle(


                 fontSize: 20,


                 color: Colors.grey,


               ),


             ),


           )


         ],


       ),


     ),


   );


 }


Text('Click \u{2795} to add')
RichText( text: TextSpan( children: [ TextSpan( text: "Click ", ), WidgetSpan( child: Icon(Icons.add, size: 14), ), TextSpan( text: " to add", ), ], ), )
Center(
          child: new Container(
            padding: const EdgeInsets.all(8.0),
            height: 500.0,
            width: 500.0,
            child: new Stack(
              overflow: Overflow.visible,
              children: <Widget>[
                new Icon(Icons.pages, size: 36.0, color: Colors.red),
                new Positioned(
                  left: 20.0,
                  child: new Icon(Icons.pages, size: 36.0, color: Colors.green),
                ),
 
              ],
            ),
          ),
    )
main() {
  List customers = [];
  customers.add(Customer('Jack', 23));
  customers.add(Customer('Adam', 27));
  customers.add(Customer('Katherin', 25));

  customers.sort((a, b) => a.age.compareTo(b.age));
  print('Sort by Age: ' + customers.toString());

  customers.sort((a, b) => a.name.compareTo(b.name));
  print('Sort by Name: ' + customers.toString());
}
//Inside main.dart
return MaterialApp(
 initialRoute: WelcomeScreen.id,
 routes: {
   WelcomeScreen.id: (context) => WelcomeScreen(),
   LoginScreen.id: (context) => LoginScreen(),
   RegistrationScreen.id: (context) => RegistrationScreen(),
   ChatScreen.id: (context) => ChatScreen(),
 },
);

//Inside **** Class:
static const String id = '****';

//Inside onPressed
  onTap: () => Navigator.pushNamed(context, VideoScreen.id, arguments: {
                'chapter_name': 'Chapter $index',
              }),
              
 // In receiving side
 final  Map<String, String> received = ModalRoute.of(context).settings.arguments;
    final chapterName = received['chapter_name'];
 
import 'package:dynamicmathapp/services/auth.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:dynamicmathapp/models/user.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class Home extends StatelessWidget {
  final AuthService _auth = AuthService();
  final ref = FirebaseDatabase.instance.reference();

  @override
  Widget build(BuildContext context) {
    User user = Provider.of<User>(context);

    return Scaffold(
      backgroundColor: Colors.brown[50],
      appBar: AppBar(
        title: Text('Welcome'),
        backgroundColor: Colors.brown[400],
        elevation: 0.0,
        actions: <Widget>[
          FlatButton.icon(
            icon: Icon(Icons.person),
            label: Text('logout'),
            onPressed: () async {
              await _auth.signOut();
            },
          ),
        ],
      ),
      body: Column(
        children: <Widget>[
          Container(
            child: Text(
              'ID:' + user.uid + 'email:' + user.email,
            ),
          ),
          RaisedButton(
            child: Text('Create Record'),
            onPressed: () {
              createRecord();
            },
          ),
          RaisedButton(
            child: Text('View Record'),
            onPressed: () {
              getData();
            },
          ),
          RaisedButton(
            child: Text('Update Record'),
            onPressed: () {
              updateData();
            },
          ),
          RaisedButton(
            child: Text('Delete Record'),
            onPressed: () {
              deleteData();
            },
          ),
        ],
      ),
    );
  }

  void createRecord() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .set([
      {"length": "1:3333", "title": "Introduction 1.1"},
      {"length": "2:30", "title": "Introduction 1.2"}
    ]);
  }

  void getData() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .once()
        .then((DataSnapshot data) {
      print(data..value);
      print(data.key);
    });
  }

  void updateData() {}

  void deleteData() {}
}
final ref = FirebaseDatabase.instance.reference();

 void getData() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .once()
        .then((DataSnapshot data) {
      print(data.value);
      print(data.key);
    });
  }
  
    void createRecord() {
    ref
        .child('videos')
        .child('class_10')
        .child('chapter_1')
        .set([
      {"length": "1:3333", "title": "Introduction 1.1"},
      {"length": "2:30", "title": "Introduction 1.2"}
    ]);
  }
   final databaseReference = Firestore.instance;

 
 void createRecord() async {
    Map data = {'length': '1:30:20', 'position': '1', 'title': 'Introduction 3.'};
    await databaseReference
        .collection("class_10")
        .document('chapter_4')
        .collection('videos')
        .document()
        .setData(
           data
);

//    await databaseReference.collection("classes")
//        .document('10')
//        .collection('chapter')
//        .document('1')
//    .collection('videos')
//    .document('1')
//        .setData({
//      'title': 'Introduction 1 Sets',
//      'length': '10:20'
//    });
  }

  void getData() {
    databaseReference
        .collection("class_10")
        .document('chapter_1')
        .collection('videos')
        .getDocuments()
        .then((QuerySnapshot snapshot) {
      snapshot.documents.forEach((f) => print('${f.data}}'));
    });
  }

  void updateData() {
    try {
      databaseReference
          .collection('books')
          .document('1')
          .updateData({'description': 'Head First Flutter'});
    } catch (e) {
      print(e.toString());
    }
    databaseReference
        .collection("classes")
        .document('10')
        .collection('chapter')
        .document('1')
        .collection('videos');
  }

  void deleteData() {
    try {
      databaseReference.collection('books').document('1').delete();
    } catch (e) {
      print(e.toString());
    }
  }
bool isAnagram(String str1, String str2) {
  String normalize(String str) => (str
          .toLowerCase()
          .replaceAll(RegExp(r'[^a-z0-9]', caseSensitive: false), '')
          .split('')
            ..sort())
      .join('');
  return normalize(str1) == normalize(str2);
}
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(title: Text('IntrinsicWidth')),
    body: Center(
      child: IntrinsicHeight(
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            RaisedButton(
              onPressed: () {},
              child: Text('Short'),
            ),
            RaisedButton(
              onPressed: () {},
              child: Text('A bit Longer'),
            ),
            RaisedButton(
              onPressed: () {},
              child: Text('The Longest text button'),
            ),
          ],
        ),
      ),
    ),
  );
}
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(title: Text('IntrinsicWidth')),
    body: Center(
      child: IntrinsicWidth(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            RaisedButton(
              onPressed: () {},
              child: Text('Short'),
            ),
            RaisedButton(
              onPressed: () {},
              child: Text('A bit Longer'),
            ),
            RaisedButton(
              onPressed: () {},
              child: Text('The Longest text button'),
            ),
          ],
        ),
      ),
    ),
  );
}
import 'package:flutter/material.dart';

void main() {
  runApp(
    new MaterialApp(
      title: 'Hello World App',
      home: new myApp(),
    )
  );
}

class myApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('Hello World App'),
      ),
      body: new Center(
        child: new Text(
          'Hello, world!'
        ),
      ),
    );
  }
}
Text("Border test",
    style: TextStyle(
      inherit: true,
      fontSize: 48.0,
      color: Colors.pink,
      shadows: [
        Shadow( // bottomLeft
          offset: Offset(-1.5, -1.5),
          color: Colors.white
        ),
        Shadow( // bottomRight
          offset: Offset(1.5, -1.5),
          color: Colors.white
        ),
        Shadow( // topRight
          offset: Offset(1.5, 1.5),
          color: Colors.white
        ),
        Shadow( // topLeft
          offset: Offset(-1.5, 1.5),
          color: Colors.white
        ),
      ]
    ),
);
String capitalize(String s) {
  if (s == null || s.isEmpty) {
    return s;
  }
  return s.length < 1 ? s.toUpperCase() : s[0].toUpperCase() + s.substring(1);
}
bookmark
dashboard

Fri Oct 30 2020 01:10:04 GMT+0000 (UTC) https://stackoverflow.com/questions/57499254/flutter-reversed-listview-start-at-top

#dart
bookmark
dashboard

Thu Oct 29 2020 18:41:27 GMT+0000 (UTC) https://stackoverflow.com/questions/61919395/how-to-generate-random-string-in-dart

#dart
bookmark
dashboard

Thu Oct 29 2020 16:33:00 GMT+0000 (UTC) https://stackoverflow.com/questions/60176001/how-to-fix-wrong-rotation-of-photo-from-camera-in-flutter

#dart
bookmark
dashboard

Mon Oct 26 2020 01:08:55 GMT+0000 (UTC) https://stackoverflow.com/questions/49835146/how-to-convert-flutter-color-to-string-and-back-to-a-color

#dart
bookmark
dashboard

Fri Sep 11 2020 07:50:15 GMT+0000 (UTC)

#dart
bookmark
dashboard

Sun Aug 23 2020 19:51:15 GMT+0000 (UTC)

#dart
bookmark
dashboard

Mon Jun 15 2020 12:36:30 GMT+0000 (UTC)

#dart
bookmark
dashboard

Mon Jun 15 2020 12:36:06 GMT+0000 (UTC) https://pusher.com/tutorials/flutter-listviews

#dart
bookmark
dashboard

Mon Jun 15 2020 12:35:38 GMT+0000 (UTC)

#dart
bookmark
dashboard

Mon Jun 15 2020 12:34:47 GMT+0000 (UTC) https://pub.dev/packages/flutter_svg#-readme-tab-

#dart
bookmark
dashboard

Mon Jun 15 2020 12:34:17 GMT+0000 (UTC) https://www.freewebmentor.com/questions/does-flutter-support-negative-margin

#dart
bookmark
dashboard

Mon Jun 15 2020 12:33:46 GMT+0000 (UTC) Dart/Flutter List Tutorial with Examples

#dart
bookmark
dashboard

Mon Jun 15 2020 12:33:08 GMT+0000 (UTC)

#dart
bookmark
dashboard

Mon Jun 15 2020 12:31:36 GMT+0000 (UTC)

#dart
bookmark
dashboard

Sun Jun 14 2020 07:37:22 GMT+0000 (UTC)

#dart
bookmark
dashboard

Sun Jun 14 2020 07:08:20 GMT+0000 (UTC) https://petercoding.com/firebase/2020/02/06/get-started-with-firebase-in-flutter/

#dart
bookmark
dashboard

Sun Jun 14 2020 03:21:06 GMT+0000 (UTC)

#dart
bookmark
dashboard

Tue May 12 2020 11:03:36 GMT+0000 (UTC) https://gist.github.com/basselch/51b8a047c5c86355c5859a2e5f198fd0

#dart #flutter
bookmark
dashboard

Tue May 12 2020 11:02:17 GMT+0000 (UTC) https://stackoverflow.com/questions/48893935/how-to-remove-debug-banner-in-flutter-on-android-emulator

#dart #flutter
bookmark
dashboard

Tue Apr 28 2020 19:52:02 GMT+0000 (UTC) https://www.30secondsofcode.org/dart/s/is-anagram/

#dart
bookmark
dashboard

Wed Jan 22 2020 18:43:41 GMT+0000 (UTC) https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e

#dart #flutter #layouts
bookmark
dashboard

Wed Jan 22 2020 18:35:33 GMT+0000 (UTC) https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e

#dart #flutter #layout
bookmark
dashboard

Sun Dec 29 2019 19:42:22 GMT+0000 (UTC) https://kodestat.gitbook.io/flutter/flutter-hello-world

#android #dart #flutter #ios #helloworld
bookmark
dashboard

Thu Dec 26 2019 18:27:15 GMT+0000 (UTC) https://stackoverflow.com/questions/52146269/how-to-decorate-text-stroke-in-flutter

#dart #flutter #howto

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension