Skip to content

override extension methods #3321

Closed
Closed
@SivaramSS

Description

@SivaramSS

Request to make extension methods behave like actual class member functions. Here is an example, calling type casting Center widget and calling the extension method calls Widget extension method instead of Center extension method. This will allow developers to add functionality to the library or framework without actually modifying the library's source code.
`
import 'package:flutter/material.dart';

  void main() {
    Widget widget = Center(child: Container(width: 50, height: 50, color: Colors.yellow,),);
    widget.foo();
    runApp(widget);
  }
  
  extension WidgetExtension on Widget {
    void foo() {
      print("Widget.foo");
    }
  }
  
  extension CenterWidgetExtension on Center {
    void foo() {
      print("Center.foo");
      child?.foo();
    }
  }
  
  extension ContainerWidgetExtension on Container {
    void foo() {
      print("Container.foo");
      child?.foo();
    }
  }

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions