I want to create a base class for my Flutter widgets:

import 'package:flutter/widgets.dart';

abstract class State extends State {
  @override
  Widget build(BuildContext context) {
    // ...
  }
  // ...
}

Like this, it results in the error "State' can't extend itself." which makes perfect sense. To fix it I can do this:

import 'package:flutter/widgets.dart' as base;

abstract class State extends base.State {

But now I have to prefix all other framework classes with "base.". Is there a way to alias just the State class and use everything else without a prefix?


Solution 1: Rafał G.

This seems to have worked:

import 'package:flutter/material.dart';
import 'package:flutter/material.dart' as base show State;

abstract class State<T extends StatefulWidget> extends base.State {
  @override
  Widget build(BuildContext context) {
    // ...
  }
}