Comments (3)
Did you setup MaterialApp?
MaterialApp(
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: S.delegate.supportedLocales,
from gen_lang.
Will closed it if no response
from gen_lang.
@KingWu Thank you for the pub.
I get similar if not the same error when calling S.of(context).card_0_0 for homepage title.
Here is the whole log:
I/flutter ( 7576): The following NoSuchMethodError was thrown building MyApp(dirty):
I/flutter ( 7576): The getter 'card_0_0' was called on null.
I/flutter ( 7576): Receiver: null
I/flutter ( 7576): Tried calling: card_0_0
I/flutter ( 7576):
I/flutter ( 7576): The relevant error-causing widget was:
I/flutter ( 7576): MyApp file:///home/joze/coding/flutterProjects/package_test/lib/main.dart:5:23
I/flutter ( 7576):
I/flutter ( 7576): When the exception was thrown, this was the stack:
I/flutter ( 7576): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
I/flutter ( 7576): #1 MyApp.build (package:package_test/main.dart:31:45)
I/flutter ( 7576): #2 StatelessElement.build (package:flutter/src/widgets/framework.dart:4291:28)
I/flutter ( 7576): #3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15)
I/flutter ( 7576): #4 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
I/flutter ( 7576): #5 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
I/flutter ( 7576): #6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
I/flutter ( 7576): #7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
I/flutter ( 7576): #8 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
I/flutter ( 7576): #9 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:1028:16)
I/flutter ( 7576): #10 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:999:5)
I/flutter ( 7576): #11 RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:942:17)
I/flutter ( 7576): #12 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2412:19)
I/flutter ( 7576): #13 RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:941:13)
I/flutter ( 7576): #14 WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:819:7)
I/flutter ( 7576): #15 WidgetsBinding.scheduleAttachRootWidget.<anonymous closure> (package:flutter/src/widgets/binding.dart:804:7)
I/flutter ( 7576): #24 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
I/flutter ( 7576): #25 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
I/flutter ( 7576): #26 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
I/flutter ( 7576): (elided 8 frames from package dart:async and package dart:async-patch)
I/flutter ( 7576):
I/flutter ( 7576): ════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following NoSuchMethodError was thrown building MyApp(dirty):
The getter 'card_0_0' was called on null.
Receiver: null
Tried calling: card_0_0
The relevant error-causing widget was:
MyApp file:///home/joze/coding/flutterProjects/package_test/lib/main.dart:5:23
When the exception was thrown, this was the stack:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1 MyApp.build (package:package_test/main.dart:31:45)
#2 StatelessElement.build (package:flutter/src/widgets/framework.dart:4291:28)
#3 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15)
#4 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
...
════════════════════════════════════════════════════════════════════════════════════════════════════
Example app
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:package_test/generated/i18n.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
supportedLocales: S.delegate.supportedLocales,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
/*** IT FAILS BELOW THIS COMMENT ***/
home: MyHomePage(title: S.of(context).card_0_0),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
S.of(context).card_0_0, // IT WORKS HERE
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
from gen_lang.
Related Issues (20)
- allow multiple parameters HOT 2
- Intelij Usage: pub run gen_lang:generate fails HOT 4
- Best way to get all strings and save it in array? HOT 1
- Next line separator while generating text with \n HOT 1
- When I'm trying to set S.of(context).text to AppBar always en location
- Strings are null at UI tests HOT 3
- Feature request: commenting
- Support easy_localizaton translation syntax
- Fixed sort
- The value 'null' can't be assigned to the parameter type 'I18nOption' because 'I18nOption' is not nullable. HOT 1
- Support for Null Safety HOT 1
- Upgrade args Package HOT 2
- Support for nested JSON properties
- Build Errors in Null Safety Project Dart 2.13 HOT 1
- Version solving failed with firebase packages
- Usage in BottomNavigationBarItem HOT 2
- error when try to run the app HOT 1
- Improvement idea: support object grouping HOT 2
- Avoid using braces in interpolation when not needed
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gen_lang.