laTruffe79 / AdheosMobileApp

0 stars 0 forks source link

Buildcontext bad practice #1

Open g-apparence opened 1 year ago

g-apparence commented 1 year ago

don't pass context, Context are huge objects and should not be copied along the widget tree

import 'package:flutter/material.dart';

class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final IconData icon;
  final Color color;
  final String routeName;
  _final BuildContext context;_ // DELETE THIS
laTruffe79 commented 1 year ago

Corrigé comme ceci :

class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
  final String title;
  final IconData icon;
  final Color color;
  final String routeName;
  //final BuildContext context;

  const MyAppBar({
    Key? key,
    required BuildContext context,
    required this.title,
    required this.icon,
    required this.color,
    required this.routeName,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AppBar(
      forceMaterialTransparency: true,...
g-apparence commented 1 year ago

Non vire toute les ref au BuildContext il en reste dans ton constructeur