Author: saqibkhan

  • Ongoing Development (2023)

    Flutter remains actively developed, with the community contributing to its growth. The focus continues to be on enhancing performance, developer experience, and expanding platform support, including desktop and embedded systems.

  • Using Streams with Transformations

    This example shows how to transform data in a stream.

    import 'dart:async';
    
    void main() {
      var controller = StreamController<int>();
    
      // Listen to the stream
      controller.stream
    
      .map((number) => number * number) // Transform numbers to their squares
      .listen((squared) {
    print('Squared: $squared');
    }); // Add data to the stream for (var i = 1; i <= 5; i++) {
    controller.add(i);
    } controller.close(); }
  • Using Isolates for Parallel Execution

    This example demonstrates how to use isolates for parallel execution in Dart.

    import 'dart:async';
    import 'dart:io';
    import 'dart:convert';
    
    void isolateEntry(SendPort sendPort) {
      var receivePort = ReceivePort();
      sendPort.send(receivePort.sendPort);
      
      receivePort.listen((message) {
    
    if (message is int) {
      var result = message * message;
      sendPort.send(result);
    }
    }); } Future<void> main() async { var receivePort = ReceivePort(); await Isolate.spawn(isolateEntry, receivePort.sendPort); var sendPort = await receivePort.first as SendPort; print('Sending numbers to isolate for squaring:'); for (var i = 1; i <= 5; i++) {
    sendPort.send(i);
    var squared = await receivePort.first;
    print('Squared: $squared');
    } }
  • Creating a Simple Command-Line Application

    This example creates a simple command-line calculator.

    import 'dart:io';
    
    double add(double a, double b) => a + b;
    double subtract(double a, double b) => a - b;
    double multiply(double a, double b) => a * b;
    double divide(double a, double b) {
      if (b == 0) {
    
    throw Exception('Cannot divide by zero');
    } return a / b; } void main() { print('Simple Calculator'); print('Enter two numbers:'); var input1 = stdin.readLineSync(); var input2 = stdin.readLineSync(); double num1 = double.parse(input1!); double num2 = double.parse(input2!); print('Choose an operation: +, -, *, /'); var operation = stdin.readLineSync(); double result; switch (operation) {
    case '+':
      result = add(num1, num2);
      break;
    case '-':
      result = subtract(num1, num2);
      break;
    case '*':
      result = multiply(num1, num2);
      break;
    case '/':
      result = divide(num1, num2);
      break;
    default:
      print('Invalid operation');
      return;
    } print('Result: $result'); }
  • Flutter 3.0 (May 2022)

    This release brought further improvements, including enhanced support for desktop and mobile platforms, as well as updates to the Flutter DevTools suite. It also introduced new features for integrating with the latest versions of iOS and Android.

  • Basic HTTP Client

    This example demonstrates how to make an HTTP GET request and handle JSON data.

    import 'dart:convert';
    import 'dart:io';
    
    Future<void> fetchPosts() async {
      var url = 'https://jsonplaceholder.typicode.com/posts';
      var httpClient = HttpClient();
    
      try {
    
    var request = await httpClient.getUrl(Uri.parse(url));
    var response = await request.close();
    if (response.statusCode == 200) {
      var jsonData = await response.transform(utf8.decoder).join();
      var posts = json.decode(jsonData);
      print('Fetched ${posts.length} posts:');
      for (var post in posts) {
        print('Title: ${post&#91;'title']}');
      }
    } else {
      print('Error: ${response.statusCode}');
    }
    } catch (e) {
    print('Exception: $e');
    } finally {
    httpClient.close();
    } } void main() { fetchPosts(); }
  • Generic Classes

    This example demonstrates the use of generics to create a stack data structure.

    class Stack<T> {
      List<T> _elements = [];
    
      void push(T element) {
    
    _elements.add(element);
    print('Pushed: $element');
    } T pop() {
    if (_elements.isEmpty) {
      throw Exception('Stack is empty');
    }
    var element = _elements.removeLast();
    print('Popped: $element');
    return element;
    } bool get isEmpty => _elements.isEmpty; } void main() { var intStack = Stack<int>(); intStack.push(1); intStack.push(2); intStack.pop(); var stringStack = Stack<String>(); stringStack.push('Hello'); stringStack.push('World'); print('Popped from string stack: ${stringStack.pop()}'); }
  • Continued Growth and Ecosystem Expansion (2021-2022)

    Flutter gained a strong following in the developer community, supported by a rich ecosystem of packages and plugins. The Flutter team continued to refine the toolkit with regular updates, improved tooling, and enhanced performance.

  • Flutter 2.0 (March 2021)

    Flutter 2.0 was released with major enhancements, including stable support for web and desktop applications, improved performance, and a more extensive set of widgets. The announcement emphasized Flutter’s versatility for building apps across multiple platforms.

  • Flutter for Web (2019)

    In 2019, Google announced experimental support for building web applications with Flutter, expanding its capabilities beyond mobile. This laid the groundwork for Flutter’s future cross-platform capabilities.