Salem
Salem

Reputation: 43

Flutter UpperCamelCase

I'm new to flutter and I made my main.dart route to my splashscreen. In my main.dart, it accepted the name splashscreen() but in my splashscreen.dart it kept flagging the error "Name types using UpperCamelCase" when I named my class splashscreen.

Here is my main.dart

import 'package:flutter/material.dart';
import 'Routes/splashscreen.dart';

void main (){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp ({Key? key}) : super(key: key)
 
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "DoyarPay",

      home: splashscreen(),
      
    );
  }
}

Here is my splashscreen.dart

import 'package:flutter/material.dart';


class splashscreen extends StatefulWidget {
  const splashscreen({ Key? key }) : super(key: key);

  @override
  _splashscreenState createState() => _splashscreenState();
}

class _splashscreenState extends State<splashscreen> {
  @override
  Widget build(BuildContext context) {
    return Container(
      
    );
  }
}

On the splashscreen.dart it gives the "Name types using UpperCamelCase" error. Can anyone help me out on this. Thanks

Upvotes: 3

Views: 5625

Answers (4)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63594

For class name in dart, suggest using CamelCase means it will start with an uppercase letter and the next word's 1st letter will be uppercase as well.

In your case splashscreen which starts with s which is lowercase. Appropriate will be SplashScreen.

For file name, we use snake_case. In this case splashscreen.dart will be splash_screen.dart

Learn more about

Upvotes: 1

Picchio
Picchio

Reputation: 425

Classes in dart has to be in UpperCamelCase. Probably the linter doesn't detect the "error" (is not an error, you are just violating a convention) in your main.dart but it does during class declaration.

To follow dart standards just change the code using UpperCamelCase consistently:

return MaterialApp(
  debugShowCheckedModeBanner: false,
  title: "DoyarPay",

  home: SplashScreen(),
  
);


import 'package:flutter/material.dart';


class SplashScreen extends StatefulWidget {
  const SplashScreen({ Key? key }) : super(key: key);

  @override
  _SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
  @override
  Widget build(BuildContext context) {
    return Container(
      
    );
  }
}

Upvotes: 0

Yasine Romdhane
Yasine Romdhane

Reputation: 626

Widgets always start with uppercase letter so change your splashscreen to Splashscreen, not only widgets but classes as well

import 'package:flutter/material.dart';
import 'Routes/splashscreen.dart';

void main (){
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp ({Key? key}) : super(key: key)
 
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: "DoyarPay",

      home: Splashscreen(),
      
    );
  }
}

    

And your splashscreen.dart

import 'package:flutter/material.dart';
    
    
    class Splashscreen extends StatefulWidget {
      const Splashscreen({ Key? key }) : super(key: key);
    
      @override
      _SplashscreenState createState() => _SplashscreenState();
    }
    
    class _SplashscreenState extends State<Splashscreen> {
      @override
      Widget build(BuildContext context) {
        return Container(
          
        );
      }
    }

Upvotes: 0

esentis
esentis

Reputation: 4666

It is "accepted" but the warning indicates that you should follow some specific naming conventions. You should definetely check here which has more details about Effective Dart.

Upvotes: 1

Related Questions