Skip to content

Instantly share code, notes, and snippets.

@AlexV525
Created April 2, 2020 12:42
Show Gist options
  • Save AlexV525/23d195f5926aa831e661a4c8c89ef4b6 to your computer and use it in GitHub Desktop.
Save AlexV525/23d195f5926aa831e661a4c8c89ef4b6 to your computer and use it in GitHub Desktop.
Why no error with static varibale?
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
ScreenUtil.init(context);
print(Themes.xs);
return Container();
}
}
class ScreenUtil {
ScreenUtil._();
static ScreenUtil _instance;
factory ScreenUtil() {
return _instance;
}
static void init(BuildContext context) {
if (_instance == null) {
_instance = ScreenUtil._();
}
}
num setSp(num value) => value;
}
extension ScreenUtilExtension on num {
num get sp => ScreenUtil().setSp(this);
}
class Themes {
static final xs = 10.sp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment