1

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?

1

1 Answer 1

0

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) {
    // ...
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.