1

I have this on scaffold_context.dart:

import 'package:flutter/material.dart';

extension Context on Scaffold {

  static Scaffold builder({ AppBar appBar, Function (BuildContext context) buildContext, Widget body }) {
    return Scaffold(
      appBar: appBar, 
      body: Builder(builder: (context) { 
        buildContext(context); 
        return body; 
      })
    );
  }

}

But when I tried to call it on my UI Widget:

import 'scaffold_context.dart';
...

  BuildContext _context;
  @override
  Widget build(BuildContext context) {
    return Scaffold.builder(
      appBar: AppBar(title: "Hello world"),
      buildContext: (context) => _context = context,
      body: Center(child: Text("Hello world")
    );
  }

I got an error:

The method 'builder' isn't defined for the class 'Scaffold'.

How am I supposed to use this extension?

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124

1 Answers1

0

Forget about it. Apparently, I have to call my extension's name to access the static function. So, I have to access Context.builder instead of Scaffold.builder.

Chen Li Yong
  • 5,459
  • 8
  • 58
  • 124