FlutterLab: Error: Null safety features are disabled for this library - flutter

I am using FlutterLab but encounter the below error:
⭐ Build started at Tuesday, August 31st 2021, 10:55:04AM +10:00 ⭐
🏁 Build finished at Tuesday, August 31st 2021, 10:55:15AM +10:00 🏁
❌ Build failed. Check the logs below
Compile failed
/lib/main.dart:24:21: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.12 or higher.
const MyDiary({Key? key}) : super(key: key);
^
No branch
with the below code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
// Application name
title: 'Flutter Hello World',
// Application theme data, you can set the colors for the application as
// you want
theme: ThemeData(
primarySwatch: Colors.blue,
),
// A widget which will be started on application startup
home: MyDiary(),
);
}
}
class MyDiary extends StatelessWidget {
const MyDiary({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container();
}
}
How can I fix the code?

Solution: sdk: ">=2.12.0 <3.0.0" in pubspecs.yml

Related

Flutter: Getx translation fall without restarting the app

I'm using GetX package with my projects, this time some thing wrong happened in the translation, I have two languages (En - Ar), so when I press on the button that switch the language, it translate the most of the app and change the direction from ltr to rtl automatically, but still showing some words in the last language until I restart the app!!!
This is the example when I tried to switch from Ar to En, and before restarting the app.
And this image, is after restarting, every thing works good!!!
Here parts of my code, maybe help:
class LocaleController extends GetxController {
static LocaleController instance = LocaleController();
Locale? language;
AppServices appServices = Get.find();
changeLanguage(String langCode) {
Locale locale = Locale(langCode);
AppServices.sharedPreferences?.setString('lang', langCode);
Get.updateLocale(locale);
}
Locale? initialLang = AppServices.sharedPreferences?.getString('lang') == null
? Get.deviceLocale
: Locale(AppServices.sharedPreferences!.getString('lang')!);
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await initialServices();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
LocaleController controller = Get.put(LocaleController());
return GetMaterialApp(
initialBinding: Binding(),
debugShowCheckedModeBanner: false,
title: 'Super Market',
translations: Translation(),
locale: controller.initialLang,
initialRoute: AppRoutes.initial,
getPages: AppRoutes.routes,
);
}
}
So what is the problem with it?

Can we build a project in flutter with different ui packages for different platforms

I want to build a flutter project, in that
for windows using fluent ui
for macos using macos ui and
for mobile apps using material ui.
Inner content will be the same for all platform just the layout and features makes difference.
so can i do that, and if yes then whats the approch...
I have tried to build some demo projects, but as soon as I integrate another platforms ui or their features, the project gets crash.
I expect the flow in that I can make platform according ui seprate for all platforms and the screens will be in common.
This question may be answered with personal opinions but anyway , for create multiplatform app in flutter , your difficult task is handle UI on multi-screen size and responsive it .
you can using responsive_builder package and flutter_screenutil .
in some conditions need another way to use an package .
for using responsive_builder on web and android device use this trick:
main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Builder(builder: (context) {
return kIsWeb
? const MainWidget()
: const ScreenUtilsWidget(widget: MainWidget());
});
}
}
class ScreenUtilsWidget extends StatelessWidget {
const ScreenUtilsWidget({Key? key, required this.widget}) : super(key: key);
final Widget widget;
#override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: (context, child) {
return widget;
});
}
}
class MainWidget extends StatelessWidget {
const MainWidget({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
// blablabla
);
}
}
and for using in widgets do like below:
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
ScreenTypeLayout(
// you can define custom breakpoint for any widget .
breakpoints: MainSizes.digitalProfileBreakpoints,
desktop: Stack(//blablabla),
tablet: Stack((//blablabla),
mobile: Stack((//blablabla),
)
],
)),
);
}
You maybe need the dart:html handles in all app, but this file are limited on the web (or You need to do something different on the web than on an Android device!).
you can create 3 file and handles this mode.
file web.dart :
import 'dart:html' as html;
void reload() {
html.window.location.reload();
}
String cookie = "";
file native.dart :
void reload() {}
String cookie = "";
file switch_native_web.dart :
import 'native.dart' if (dart.library.html) 'web.dart' as switch_value;
class SwitchNativeWeb {
static String cookie = switch_value.cookie;
static void reloadWeb() {
switch_value.reload();
}
}

why flutter web_view showing error on initial Url?

I install the web_view flutter plugin and set minTargetSDk to 20 but still, I face an error on initialurl.
Here is the code snippet:
Kindly change you page name from WebView to any other.
Or you can do it as below:
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart' as wv;
class WebView extends StatefulWidget {
const WebView({Key? key}) : super(key: key);
#override
State<WebView> createState() => _WebViewState();
}
class _WebViewState extends State<WebView> {
#override
Widget build(BuildContext context) {
return wv.WebView(
initialUrl: 'https://flutter.dev/',
);
}
}

flutter getx package not working, showing error

I recently upgraded flutter. After upgrading, when I going to use Get it's showing down error.
without adding get my project work fine.
Codes
import 'package:flutter/material.dart';
import 'package:flutterfire_auth/src/homepage.dart';
import 'package:get/get.dart';
void main() {
return runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter App',
debugShowCheckedModeBanner: false,
home: Homepage(),
);
}
}
errors
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/get-3.15.0/lib/get_navigation/src/extension_navigation.dart:235:37: Error: No named parameter with the name 'shadowThemeOnly'.
final theme = Theme.of(context, shadowThemeOnly: true);
^^^^^^^^^^^^^^^
/C:/src/flutter/packages/flutter/lib/src/material/theme.dart:119:20: Context: Found this candidate, but the arguments don't match.
static ThemeData of(BuildContext context) {
^^
add pub dependency extension in vscode "Pubspec Dependency Search" ,it will help in automitacally add "get" dependency

When assembleDebug Out of Memory error is thrown

So I'm new to flutter and dart.I've made multiple android apps and I am pretty familiar with coding but I just can't get to know flutter. I use Android Studio as Ide and when I try to compile my code , on the assembleDebug part, This error is thrown:
c:\b\s\w\ir\k\src\third_party\dart\runtime\vm\zone.cc: 54: error: Out
of memory.
version=2.4.0 (Wed Jun 19 11:53:45 2019 +0200) on "windows_x64"
thread=1336, isolate=main(0000029506C2CDE0)
pc 0x00007ff7b33d2b1b fp 0x000000d10cbfb0a0 Unknown symbol
-- End of DumpStackTrace
For now, I haven't done anything to fix the problem because I don't know why
main.dart
import 'package:flutter/material.dart';
import 'constants.dart';
import 'package:flutter_svg/flutter_svg.dart';
void main() {
runApp(UnitConverterApp());
}
//on create
class UnitConverterApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Distivity Todolist',
theme: Constants.getTheme(),
home: CategoryRoute(),
);
}
}
class CategoryRoute extends StatefulWidget {
const CategoryRoute();
#override
_CategoryRouteState createState() => _CategoryRouteState();
}
class _CategoryRouteState extends State<CategoryRoute> {
/// Function to call when a [Category] is tapped.
void _onCategoryTap() {
setState(() {
});
}
#override
Widget build(BuildContext context) {
return Center(
child: InkWell(
onTap: () => _onCategoryTap(),
child: SvgPicture.asset(
Constants.add,
semanticsLabel: 'ad'
),
)
);
}
}
constants.dart
import 'package:flutter/material.dart';
class Constants{
static ThemeData getTheme(){
return ThemeData(
primaryColor: colorSwatch,
);
}
static const primaryColor = 0xff4FB484;
static ColorSwatch colorSwatch = ColorSwatch(primaryColor, const<String,Color>{
"primary_color": Color(primaryColor),
"primary_dark":Color(0xff306D50),
"black_16": Color(0xff161616),
"black_20":Color(0xff202020),
"the_blackest":Color(0xff000000),
"color_white":Color(0xffF7F7F7),
"the_whitest":Color(0xffffffff)
});
static const String add = 'assets/add.svg';
}
pubspec.yaml
name: distivity_todolist
description: A new Flutter application.
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_svg: 0.13.1
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/add.svg