Created
April 2, 2020 12:42
-
-
Save AlexV525/23d195f5926aa831e661a4c8c89ef4b6 to your computer and use it in GitHub Desktop.
Why no error with static varibale?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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