I was trying to do a Color Picker for my app in flutter...
i installed the Mtaerial Color Picker package from pub dev...
then i tried to make a Provider like i made for my Dark Mode...
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ThemeProvider with ChangeNotifier {
ThemeData _selectedTheme;
int primaryValue;
static Color secondaryColor;
ThemeProvider({
bool isDarkMode,
int primaryValue,
}) {
this._selectedTheme = isDarkMode ? dark : light;
this.primaryValue = colorValue;
}
static int colorValue;
ThemeData light = ThemeData.light().copyWith(
primaryColor: Color(colorValue) ?? Colors.teal[700],
);
ThemeData dark = ThemeData.dark().copyWith();
void changeColor(int value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
colorValue = value;
primaryValue = colorValue;
print(colorValue);
prefs.setInt('PrimaryColor', primaryValue);
notifyListeners();
}
void swapTheme() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (_selectedTheme == dark) {
_selectedTheme = light;
prefs.setBool('isDarkTheme', false);
print(prefs.getBool('isDarkTheme'));
} else {
_selectedTheme = dark;
prefs.setBool('isDarkTheme', true);
print(prefs.getBool('isDarkTheme'));
}
notifyListeners();
}
ThemeData get getTheme => _selectedTheme;
}
the swapTheme() is for my dark Mode and the change Color it is For my problem i get the Color int from my picker like that:
MaterialColorPicker(
circleSize: 50,
selectedColor:
_selectedColor ?? Colors.teal[700],
onColorChange: (Color color) {
setState(() {
_selectedColor = color;
String primaryColorString =
_selectedColor.toString();
String valueString = primaryColorString
.split('(0x')[1]
.split(')')[0];
int value =
int.parse(valueString, radix: 16);
themeProvider.changeColor(value);
});
},
),
and when i choose a color it just activate the change color function where it should rebuild my app because i am using provider in my main.dart thats how my Dark Mode is working
return runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (BuildContext context) => ThemeProvider(
isDarkMode: prefs.getBool('isDarkTheme') ?? false,
primaryValue: prefs.getInt('PrimaryColor') ?? 4293467747,
),
),
],
child: MyApp(),
),
);
}
return Consumer<ThemeProvider>(
builder: (context, themeProvider, _) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: themeProvider.getTheme,
tho its giving me This Error
The method '&' was called on null.
Receiver: null Tried calling:
&(4294967295)
and this too
Bad state: Tried to read a provider that threw during the creation of its value.
The exception occurred during the creation of type ThemeProvider.
okay so it should be done this way this is my darkMode changer the theme one :
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class DarkModeProvider with ChangeNotifier {
ThemeData _selectedTheme;
DarkModeProvider({
bool isDarkMode,
}) {
this._selectedTheme = isDarkMode ? dark : light;
}
ThemeData light = ThemeData.light();
ThemeData dark = ThemeData.dark();
void swapDarkMode() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (_selectedTheme == dark) {
_selectedTheme = light;
prefs.setBool('isDarkMode', false);
} else {
_selectedTheme = dark;
prefs.setBool('isDarkMode', true);
}
notifyListeners();
}
ThemeData get getTheme => _selectedTheme;
}
my color changer file:
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class ColorChanger with ChangeNotifier {
int primary;
int secondary;
ColorChanger({
this.primary,
this.secondary,
});
void changePrimaryColor(int prim) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
primary = prim;
prefs.setInt('Primary', primary);
notifyListeners();
}
void changeSecondaryColor(int second) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
secondary = second;
prefs.setInt('Secondary', secondary);
notifyListeners();
}
int get getPrimColor => primary;
int get getSecondColor => secondary;
}
where i change both is my setting page you put the widgets in any page...
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
import '../providers/color_provider.dart';
import '../providers/dark_mode_provider.dart';
class SettingsScreen extends StatefulWidget {
static const routeName = '/settings';
#override
_SettingsScreenState createState() => _SettingsScreenState();
}
class _SettingsScreenState extends State<SettingsScreen> {
bool _darkValue = false;
Color _selectedPrimaryColor;
Color _selectedSecondaryColor;
_onBackPressed() {
Navigator.of(context).pushReplacementNamed('/home');
}
getSharedPrefs() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var value = prefs.getBool('isDarkMode') ?? false;
if (value == false) {
setState(() {
_darkValue = false;
});
} else {
setState(() {
_darkValue = true;
});
}
}
#override
void initState() {
super.initState();
getSharedPrefs();
}
#override
Widget build(BuildContext context) {
DarkModeProvider darkModeProvider = Provider.of<DarkModeProvider>(
context,
listen: false,
);
ColorChanger colorChanger = Provider.of<ColorChanger>(
context,
listen: false,
);
return WillPopScope(
onWillPop: () {
return _onBackPressed();
},
child: Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
_onBackPressed();
},
),
),
body: Container(
margin: EdgeInsets.symmetric(
horizontal: 20,
vertical: 5,
),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
child: Text(
'Dark Mode',
style: TextStyle(
fontSize: 20,
),
),
),
),
Switch(
value: _darkValue,
onChanged: (toggle) {
darkModeProvider.swapDarkMode();
getSharedPrefs();
}),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
child: Text(
'Primary Colors',
style: TextStyle(
fontSize: 20,
),
),
),
),
TextButton(
onPressed: () {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
actions: <Widget>[
IconButton(
onPressed: () {
Navigator.of(context).pop(true);
},
icon: Icon(Icons.check),
),
],
content: SingleChildScrollView(
child: Container(
height:
MediaQuery.of(context).size.height * 0.35,
child: MaterialColorPicker(
circleSize: 50,
selectedColor:
Color(colorChanger.getPrimColor) ??
Colors.teal[700],
onColorChange: (Color color) {
setState(() {
_selectedPrimaryColor = color;
colorChanger.changePrimaryColor(
_selectedPrimaryColor.value);
});
},
),
),
),
);
},
);
},
child: CircleAvatar(
child: Icon(
Icons.color_lens,
color: Colors.white54,
),
backgroundColor:
Color(colorChanger.getPrimColor) ?? Colors.teal[700],
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
child: Text(
'Secondary Colors',
style: TextStyle(
fontSize: 20,
),
),
),
),
TextButton(
onPressed: () {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
actions: <Widget>[
IconButton(
onPressed: () {
Navigator.of(context).pop(true);
},
icon: Icon(Icons.check),
),
],
content: SingleChildScrollView(
child: Container(
height:
MediaQuery.of(context).size.height * 0.35,
child: MaterialColorPicker(
circleSize: 50,
selectedColor:
Color(colorChanger.getSecondColor) ??
Colors.amber,
onColorChange: (Color color) {
setState(() {
_selectedSecondaryColor = color;
colorChanger.changeSecondaryColor(
_selectedSecondaryColor.value);
});
},
),
),
),
);
},
);
},
child: CircleAvatar(
child: Icon(
Icons.color_lens,
color: Colors.white54,
),
backgroundColor:
Color(colorChanger.getSecondColor) ?? Colors.amber,
),
),
],
),
],
),
),
),
);
}
}
here i used shared prefs.. so i can see my switch button functioning with the shared prefs
and here how you can use the both provider in the Themedata in the main dart:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:todo/providers/task_provider.dart';
import 'package:todo/screens/add_task_screen.dart';
import './screens/settings_screen.dart';
import './providers/color_provider.dart';
import './providers/dark_mode_provider.dart';
import './screens/home_screen.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
return runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(
create: (BuildContext context) => TaskProvider(),
),
ChangeNotifierProvider(
create: (BuildContext context) => DarkModeProvider(
isDarkMode: prefs.getBool('isDarkTheme') ?? false,
),
),
ChangeNotifierProvider(
create: (BuildContext context) => ColorChanger(
primary: prefs.getInt('Primary') ?? Colors.teal[700].value,
secondary: prefs.getInt('Secondary') ?? Colors.amber.value,
),
),
],
child: MyApp(),
),
);
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
return Consumer2<DarkModeProvider, ColorChanger>(
builder: (context, darkmode, colorChanger, _) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: darkmode.getTheme.copyWith(
primaryColor: Color(colorChanger.getPrimColor),
accentColor: Color(colorChanger.getSecondColor),
),
home: HomeScreen(),
routes: {
HomeScreen.routeName: (context) => HomeScreen(),
SettingsScreen.routeName: (context) => SettingsScreen(),
AddTaskScreen.routeNamed: (context) => AddTaskScreen(),
},
);
});
}
}
i guess its helpful i used it in my app..
thank you guys..
Related
I have a 2 tab screen where I want to dynamically rebuild the content depending on user's interactions. On the first tab there are multiple states which I try to handle by setting a current step name using model and provider. For the second screen after pressing a button I get the print message in a console but the content of CupertinoTabView remains unchanged.
Minimum runnable code snippet:
main.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:my_app/screens/login.dart';
import 'package:my_app/screens/tab_bar.dart';
import 'package:my_app/models/model.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
return runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => Model(),
),
],
child: CupertinoApp(
theme: const CupertinoThemeData(
brightness: Brightness.light,
scaffoldBackgroundColor: CupertinoColors.white,
),
initialRoute: '/',
routes: {
'/': (context) => LoginScreen(),
'/tab_bar': (context) => TabBarScreen(),
//'/add_item': (context) => AddItemScreen(),
},
),
);
}
}
login.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:my_app/models/model.dart';
class LoginScreen extends StatelessWidget {
final model = Model();
#override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('app',),
),
child: Container(
alignment: FractionalOffset.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
child: Text('next'),
onPressed: (){
model.setStep('step1');
Navigator.pushNamed(context, '/tab_bar');
},
style: ElevatedButton.styleFrom(
primary: CupertinoColors.white,
side: BorderSide(color: Colors.blue, width: 2.0)
),
),
]
),
),
);
}
}
tab_bar.dart
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:my_app/models/model.dart';
class TabBarScreen extends StatefulWidget {
#override
State createState() => TabBarScreenState();
}
class TabBarScreenState extends State<TabBarScreen> {
final model = Model();
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
print(model.getStep);
return Consumer<Model>(
builder: (context, model, _) => CupertinoTabScaffold(
tabBar: CupertinoTabBar(
backgroundColor: CupertinoColors.white,
inactiveColor: Colors.blue,
activeColor: Colors.blueAccent,
border: const Border(
top: BorderSide(
color: CupertinoColors.activeBlue,
width: 2.0,
),
),
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.favorite_outline_outlined),
),
BottomNavigationBarItem(
icon: Icon(Icons.more_vert_sharp),
),
],
),
tabBuilder: (context, index) {
late final CupertinoTabView returnValue;
switch (index) {
case 0:
if (model.getStep == 'step1') {
print('step1');
returnValue = CupertinoTabView(builder: (context) {
return CupertinoPageScaffold(
child: SafeArea(
child: GestureDetector(
onTap: (){ },
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
margin: const EdgeInsets.only(bottom: 15.0),
child: FloatingActionButton(
onPressed: () { model.setStep('step2'); setState(() {
}); },
tooltip: 'step2',
child: Icon(Icons.add),
backgroundColor: CupertinoColors.white,
foregroundColor: CupertinoColors.black,
),
),
],
),
],
),
),
),
);
});
}
else if (model.getStep == 'step2') {
print('step2');
returnValue = CupertinoTabView(builder: (context) {
return CupertinoPageScaffold(
child: SafeArea(
child: Column(
children: <Widget> [
Text('step2'),
],
),
),
);
});
}
else {
returnValue = CupertinoTabView(builder: (context) {
return Container();
});
}
break;
case 1:
returnValue = CupertinoTabView(builder: (context) {
return CupertinoPageScaffold(
child: Text("Tab2"),
);
});
break;
}
return returnValue;
},
),
);
}
}
model.dart
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
class Model extends ChangeNotifier {
static String currentStep = 'login';
// login
// step1 - step1
// step2 - step2
String get getStep {
return currentStep;
}
void setStep(String step) {
currentStep = step;
notifyListeners();
}
}
I want the tab to rebuild on pressing a button from step1 to show the step2 content. In a console I can see the print of 'step2' when pressing, but the actual tab remains unchanged.
Appreciate your help
Since nobody have answered I figured it out on my own.
The resolution is to use Navigator like this:
onPressed: () {
Navigator.of(context).push(
CupertinoPageRoute<void>(
builder: (BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Page 2 of tab'),
),
child: Center(
child: CupertinoButton(
child: const Text('Back'),
onPressed: () { Navigator.of(context).pop(); },
),
),
);
},
),
);
},
and therefore you won't need 'else if' conditioning.
i'm trying to implement provider in my flutter app but getting a little stuck.
It's basically a list of tasks. You should be able to double tap an existing task and edit the text. Below the task text is a counter which shows how long the task text is but it never updates when I type. Any ideas why?
task.dart
class Task {
String taskText;
bool completed;
String id = UniqueKey().toString();
Task({
this.taskText = '',
this.completed = false,
});
void toggle() {
completed = !completed;
}
}
task_data.dart
import 'dart:collection';
import 'package:flutter/foundation.dart';
import 'package:task_management/model/task.dart';
class TaskData with ChangeNotifier {
List<Task> _tasks = [];
UnmodifiableListView<Task> get tasks => UnmodifiableListView(_tasks);
void addTask(Task task) {
int index = _tasks.indexWhere((element) => element.id == task.id);
if (index == -1) {
_tasks.add(task);
} else {
_tasks[index] = task;
}
notifyListeners();
}
void toggleTask(Task task) {
task.toggle();
notifyListeners();
}
void removeTask(Task task) {
_tasks.remove(task);
notifyListeners();
}
}
main.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'model/task_data.dart';
import 'screens/home.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => TaskData(),
child: MaterialApp(
title: 'Provider Demo',
theme: ThemeData(
primarySwatch: Colors.green,
),
home: Home(),
),
);
}
}
home.dart
import 'package:flutter/material.dart';
import 'package:task_management/screens/task_list.dart';
import 'task_form.dart';
class Home extends StatelessWidget {
// create the appbar
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks'),
),
body: Container(
padding: EdgeInsets.all(20),
child: TaskList(),
),
floatingActionButton: FloatingActionButton(
child: Icon(
Icons.add,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TaskForm(
taskIndex: -1,
)));
},
),
);
}
}
task_list.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:task_management/model/task_data.dart';
import 'task_form.dart';
class TaskList extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Consumer<TaskData>(builder: (context, data, child) {
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: data.tasks.length,
itemBuilder: (context, index) {
final task = data.tasks[index];
// gesture detection
return GestureDetector(
onLongPress: () => data.removeTask(task),
onDoubleTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TaskForm(
taskIndex: index,
)));
},
child: Container(
margin: EdgeInsets.only(bottom: 10),
padding: EdgeInsets.fromLTRB(12, 5, 8, 5),
width: double.infinity,
decoration: BoxDecoration(color: Colors.black12, borderRadius: BorderRadius.circular(8)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// text field
Text(
task.taskText,
style: TextStyle(decoration: task.completed ? TextDecoration.lineThrough : null, fontSize: 16, fontWeight: FontWeight.bold),
),
// switch case
Switch(
value: task.completed,
onChanged: (c) => data.toggleTask(task),
),
],
),
),
);
},
);
});
}
}
task_form.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:task_management/model/task.dart';
import 'package:task_management/model/task_data.dart';
class TaskForm extends StatelessWidget {
final int taskIndex;
TaskForm({required this.taskIndex});
#override
Widget build(BuildContext context) {
TaskData taskProvider = Provider.of<TaskData>(context);
Task task = taskIndex != -1 ? taskProvider.tasks[taskIndex] : Task();
return Scaffold(
appBar: AppBar(
title: Text('Task Form'),
),
body: Container(
padding: EdgeInsets.all(18),
child: Column(
children: [
TextFormField(
initialValue: task.taskText,
onChanged: (c) => task.taskText = c,
),
Text(task.taskText.length.toString()),
// add button
ElevatedButton(
child: Text(
'Submit',
),
// assign action
onPressed: () {
Provider.of<TaskData>(context, listen: false).addTask(task);
Navigator.pop(context);
},
)
],
),
),
);
}
}
This happened as the Task object not notifying the changes,
Try
TextFormField(
initialValue: task.taskText,
onChanged: (c) {
task.taskText = c,
Provider.of<TaskData>(context, listen: false).notifyListeners();
}
),
I am trying to do the above in the way shown in How to pass multiple arguments in named route in flutter.
I basically want to pass 2 parameters: docid and isCaregiver to the homescreen but it shows the error that the parameter is not defined for the class. The class ScreenArguments is the class to pass 2 parameters. Please see the code.
ScreenArguments.dart
class ScreenArguments {
final String docid;
final bool isCaretaker;
ScreenArguments({this.docid, this.isCaretaker});
}
main.dart
import 'dart:ui';
import 'package:vitality/stream.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:vitality/screens/login.dart';
import 'screens/homescreen.dart';
import 'screens/chatbot.dart';
import 'screens/todo.dart';
import 'package:vitality/screens/welcome.dart';
import 'screens/register.dart';
import 'package:firebase_core/firebase_core.dart';
import 'components/ScreenArguments.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class ScreenArguments {
final String reportTitle;
final String reportFullPath;
ScreenArguments(this.reportTitle, this.reportFullPath);
}
class Router {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case Welcome.id:
return MaterialPageRoute(builder: (_) => Welcome());
case HomeScreen.id:
return MaterialPageRoute(builder: (BuildContext context) {
ScreenArguments argument = args;
return HomeScreen(
docid: argument.docid,
isCaretaker: argument.isCaretaker,
);
});
case LoginScreen.id:
return MaterialPageRoute(builder: (_) => LoginScreen());
case Register.id:
return MaterialPageRoute(builder: (_) => Register());
case ChatBot.id:
return MaterialPageRoute(builder: (_) => ChatBot());
case Todo.id:
return MaterialPageRoute(builder: (_) => Todo());
}
}
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Color(0xff222831),
accentColor: Color(0xff00adb5),
textTheme: TextTheme(
headline1: TextStyle(
fontSize: 15.0, fontFamily: 'Montserrat', color: Colors.black),
headline2: TextStyle(
fontSize: 60.0, fontFamily: 'CrimsonText', color: Colors.black),
headline3: TextStyle(
fontSize: 30.0, fontFamily: 'Lora', color: Colors.white),
headline4: TextStyle(
fontSize: 30.0, fontFamily: 'Montserrat', color: Colors.white),
),
),
initialRoute: Welcome.id,
routes: {
'test': (context) => Test(),
Welcome.id: (context) => Welcome(),
HomeScreen.id: (context) => HomeScreen(),
LoginScreen.id: (context) => LoginScreen(),
Register.id: (context) => Register(),
ChatBot.id: (context) => ChatBot(),
Todo.id: (context) => Todo()
},
);
}
}
login.dart
Button(
text: 'LOGIN AS INFIRM ',
onPressed: () {
doesElderlyExist();
print('docid after elderly function call: $docid');
if (docid == null) {
print('user does not exist');
} else {
isCaretaker = false;
Navigator.pushNamed(context, HomeScreen.id,
arguments: ScreenArguments(docid, isCaretaker));
}
}),
Error shown in main.dart
Error shown in login.dart
generateRoute function does not know that your arguments are of type ScreenArguments, you should define that explicitly:
...
case HomeScreen.id:
return MaterialPageRoute(builder: (BuildContext context) {
final argument = args as ScreenArguments;
return HomeScreen(
docid: argument.docid,
isCaretaker: argument.isCaretaker,
);
});
...
One more thing there is that you have another class defined in main.dart with the same name ScreenArguments, double-check that and remove the unused one (based on your example, the one with reportTitle and reportFullPath properties is the "wrong" one).
[![error][1]][1]
this is the error on my login.dart
[1]: https://i.stack.imgur.com/hLjUV.png
here is the code from main.dart and route.dart
import 'dart:ui';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:vitality/screens/welcome.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:vitality/components/route.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Color(0xff222831),
accentColor: Color(0xff00adb5),
textTheme: TextTheme(
headline1: TextStyle(
fontSize: 15.0, fontFamily: 'Montserrat', color: Colors.black),
headline2: TextStyle(
fontSize: 60.0, fontFamily: 'CrimsonText', color: Colors.black),
headline3: TextStyle(
fontSize: 30.0, fontFamily: 'Lora', color: Colors.white),
headline4: TextStyle(
fontSize: 30.0, fontFamily: 'Montserrat', color: Colors.white),
),
),
initialRoute: Welcome.id,
onGenerateRoute: RouteGen.generateRoute,
// routes: {
// 'test': (context) => Test(),
// Welcome.id: (context) => Welcome(),
// HomeScreen.id: (context) => HomeScreen(),
// LoginScreen.id: (context) => LoginScreen(),
// Register.id: (context) => Register(),
// ChatBot.id: (context) => ChatBot(),
// Todo.id: (context) => Todo()
// },
);
}
}
route.dart
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:vitality/screens/login.dart';
import 'package:vitality/screens/homescreen.dart';
import 'package:vitality/screens/chatbot.dart';
import 'package:vitality/screens/todo.dart';
import 'package:vitality/screens/welcome.dart';
import 'package:vitality/screens/register.dart';
import 'package:vitality/components/ScreenArguments.dart';
class RouteGen {
static Route<dynamic> generateRoute(RouteSettings settings) {
final args = settings.arguments;
switch (settings.name) {
case Welcome.id:
return MaterialPageRoute(builder: (_) => Welcome());
case HomeScreen.id:
return MaterialPageRoute(builder: (BuildContext context) {
final argument = args as ScreenArguments;
return HomeScreen(
docid: argument.docid,
isCaretaker: argument.isCaretaker,
);
});
case LoginScreen.id:
return MaterialPageRoute(builder: (_) => LoginScreen());
case Register.id:
return MaterialPageRoute(builder: (_) => Register());
case ChatBot.id:
return MaterialPageRoute(builder: (_) => ChatBot());
case Todo.id:
return MaterialPageRoute(builder: (_) => Todo());
}
}
}
login.dart
import 'package:flutter/material.dart';
import 'package:delayed_display/delayed_display.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:vitality/components/ScreenArguments.dart';
import 'package:vitality/screens/homescreen.dart';
import 'package:vitality/components/button.dart';
import 'package:vitality/components/ScreenArguments.dart';
bool isCaretaker = false;
String elderly;
String caretaker;
String carepass;
var docid;
CollectionReference main = FirebaseFirestore.instance.collection('maindb');
class LoginScreen extends StatefulWidget {
#override
_LoginScreenState createState() => _LoginScreenState();
static const String id = 'login_screen';
}
// class arguments {
// String id;
// bool isCare= false;
// arguments({this.id,this.isCare})
// }
doesCTExist() async {
print('in does caretaker exist');
main.where('caretaker', isEqualTo: caretaker).get().then(
(QuerySnapshot snapshot) => {
snapshot.docs.forEach((f) {
docid = f.reference.id;
}),
},
);
print('docid in caretaker function: $docid');
}
doesElderlyExist() async {
print('in does elderly exist');
print(elderly);
main.where('elderly', isEqualTo: elderly).get().then(
(QuerySnapshot snapshot) => {
snapshot.docs.forEach((f) {
docid = f.reference.id;
}),
},
);
print('docid in elderly function: $docid');
}
class _LoginScreenState extends State<LoginScreen> {
final _auth = FirebaseAuth.instance;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xFF602247),
toolbarHeight: 50.0,
centerTitle: true,
title: Text(
'VITALITY',
style: Theme.of(context).textTheme.headline4,
)),
backgroundColor: Colors.white,
body: Container(
height: 1000,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://www.fonewalls.com/wp-content/uploads/2019/10/Gradient-Background-Wallpaper-002-300x585.jpg'),
fit: BoxFit.cover,
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.7), BlendMode.dstATop),
)),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 24.0),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
DelayedDisplay(
delay: Duration(seconds: 1),
child: Column(children: <Widget>[
SizedBox(height: 90),
Text('INFIRM LOGIN',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20.0)),
SizedBox(height: 15.0),
Text('USERNAME',
style: Theme.of(context).textTheme.headline1),
SizedBox(height: 15.0),
TextField(
onChanged: (value) {
elderly = value;
},
),
SizedBox(height: 25.0),
Button(
text: 'LOGIN AS INFIRM ',
onPressed: () {
doesElderlyExist();
print('docid after elderly function call: $docid');
if (docid == null) {
print('user does not exist');
} else {
isCaretaker = false;
// Navigator.pushNamed(context, HomeScreen.id,
// arguments: docid, isCaretaker);
**Navigator.of(context).pushNamed('home_screen',arguments: docid,isCaretaker);**
}
}),
SizedBox(height: 95.0),
Text('CARETAKER LOGIN',
textAlign: TextAlign.left,
style: TextStyle(fontSize: 20.0)),
SizedBox(height: 15.0),
Text('USERNAME',
style: Theme.of(context).textTheme.headline1),
TextField(
onChanged: (value) {
caretaker = value;
},
),
SizedBox(height: 15.0),
Text('PASSWORD',
style: Theme.of(context).textTheme.headline1),
TextField(
onChanged: (value) {
carepass = value;
},
),
SizedBox(height: 25.0),
Button(
text: 'LOGIN AS CARETAKER',
onPressed: () async {
try {
doesCTExist();
print('docid after ct function call: $docid');
final user = await _auth.signInWithEmailAndPassword(
email: caretaker, password: carepass);
if (user != null) {
isCaretaker = true;
Navigator.pushNamed(context, HomeScreen.id,
arguments: docid);
}
} catch (e) {
print(e);
}
},
),
]),
),
],
),
),
),
),
);
}
}
i have starred the error causing line( same as screenshot)
am facing this problem for a while now and i've no flutter community in my country so am forced to post online if i get any help and i will be glad if i found one cuz am in the deployment face of this app and it is the only thing stopping from publishing and getting paid so please guys i need help
[![am getting this error for a week now][1]][1]
this is my home
import 'package:connection_status_bar/connection_status_bar.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:taxi/Driver/HomeScreen.dart';
import 'package:taxi/Driver/carInfo..dart';
import 'package:taxi/Driver/loginPage.dart';
import 'package:taxi/config.dart';
import 'package:taxi/riders/Screens/HomeScreen.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:provider/provider.dart';
import 'package:taxi/riders/Screens/PhoneAuthInfo.dart';
import 'package:taxi/riders/Screens/Profile.dart';
import 'package:taxi/riders/Screens/historyScreen.dart';
import 'package:taxi/riders/Screens/landingPage.dart';
import 'package:taxi/riders/Screens/loginPage.dart';
import 'package:taxi/riders/Screens/signUp.dart';
import 'package:taxi/riders/data/Data.dart';
import 'package:taxi/Driver/signUp.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
currentfirebaseUser = FirebaseAuth.instance.currentUser;
runApp(MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => AppData(),)
],
child: EasyLocalization(
child: MyApp(),
path: "images/resources",
saveLocale: true,
supportedLocales: [
Locale('am', 'ET'),
Locale('en', 'CA'),
Locale('en', 'US')
],
fallbackLocale: Locale('en', 'US'),
),
)
);
}
DatabaseReference userRef =
FirebaseDatabase.instance.reference().child("users");
DatabaseReference driverRef =
FirebaseDatabase.instance.reference().child("drivers");
DatabaseReference newRequestsRef =
FirebaseDatabase.instance.reference().child("Ride Request");
DatabaseReference rideRequestRef = FirebaseDatabase.instance
.reference()
.child("drivers")
.child(currentfirebaseUser.uid)
.child("newRide");
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Goosh',
theme: ThemeData(
cursorColor: Colors.black,
fontFamily: "Font regular",
primaryColor: Colors.amber,
),
builder: (context, _) => Stack(children: [
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Goosh',
theme: ThemeData(
cursorColor: Color(0xff5f86ba),
fontFamily: "Font regular",
primaryColor: Color(0xff5f86ba),
),
localizationsDelegates: context.localizationDelegates,
supportedLocales: context.supportedLocales,
locale: context.locale,
initialRoute: FirebaseAuth.instance.currentUser == null
? PhoneAuth.idScreen
: HomeScreen.idScreen,
// initialRoute: Login.idScreen,
routes: {
PhoneAuth.idScreen: (context) => PhoneAuth(),
Login.idScreen: (context) => Login(),
SignUp.idScreen: (context) => SignUp(),
HomeScreen.idScreen: (context) => HomeScreen(),
DriverSignUp.idScreen: (context) => DriverSignUp(),
DriverLogin.idScreen: (context) => DriverLogin(),
CarInfo.idScreen: (context) => CarInfo(),
DriverMainScreen.idScreen: (context) => DriverMainScreen(),
HistoryScreen.idScreen: (route) => HistoryScreen(),
PhoneAuthInfo.idScreen: (context) => PhoneAuthInfo(),
ProfilePage.idScreen: (context) => ProfilePage()
},
),
Align(
alignment: Alignment.topCenter,
child: ConnectionStatusBar(
lookUpAddress: 'google.com',
height: 32,
animationDuration: Duration(milliseconds: 100),
title: Material(
color: Colors.redAccent,
child: Text(
'Please check your internet connection',
style: TextStyle(color: Colors.white, fontSize: 16),
),
)),
)
]),
);
}
}
and this is how i navigate to this page
ListTile(
leading: Icon(Icons.local_taxi_outlined),
title: Text("My Gooshs".tr().toString()),
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => HistoryScreen()));
},
),
and this is my history screen code
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:taxi/riders/data/data.dart';
import 'package:taxi/riders/widget/historyItem.dart';
class HistoryScreen extends StatefulWidget {
static const String idScreen = "HistoryScreen";
#override
_HistoryScreenState createState() => _HistoryScreenState();
}
class _HistoryScreenState extends State<HistoryScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("History"),
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(Icons.keyboard_arrow_left),
),
),
body: History());
}
}
class History extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ListView.separated(
padding: EdgeInsets.all(0),
itemBuilder: (context, index) {
return HistoryItem(
history: Provider.of<AppData>(context, listen: false)
.tripHistoryDataList[index],
);
},
separatorBuilder: (BuildContext context, int index) => Divider(
height: 2.0,
thickness: 2.0,
),
itemCount: Provider.of<AppData>(context, listen: false).tripHistoryDataList.length,
physics: ClampingScrollPhysics(),
shrinkWrap: true,
);
}
}
and this is my single history item
import 'package:flutter/material.dart';
import 'package:taxi/riders/assistance/DriverAssistMethod.dart';
import 'package:taxi/riders/model/History.dart';
class HistoryItem extends StatelessWidget {
final History history;
HistoryItem({this.history});
#override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: Column(
children: [
Container(
child: Row(
children: <Widget>[
Image.asset(
'images/pickicon.png',
height: 16.0,
width: 16.0,
),
SizedBox(width: 18.0),
Expanded(
child: Container(
child: Text(history.pickUp,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 18.0)))),
Text(
'${history.fares}',
style: TextStyle(fontFamily: 'Font bold', fontSize: 16.0),
)
],
),
),
SizedBox(
height: 8.0,
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Image.asset(
'images/desticon.png',
height: 16.0,
width: 16.0,
),
Text(history.dropOff,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 18.0))
],
),
SizedBox(
height: 15.0,
),
Text(
DriverAssistantMethods.formatTripDate(history.createdAt),
style: TextStyle(color: Colors.grey),
)
],
),
);
}
}
and this is my provider data
import 'package:taxi/riders/model/History.dart';
import 'package:taxi/riders/model/adress.dart';
import 'package:flutter/material.dart';
class AppData extends ChangeNotifier{
Address pickupLocation, dropOffLocation;
int countTrips = 0;
List<String> tripHistoryKeys = [];
List<History> tripHistoryDataList = [];
void updatePickUpLocationAddress(Address pickUpAddress)
{
pickupLocation = pickUpAddress;
notifyListeners();
}
void updatedropOffLocationAddress(Address dropOffAddress)
{
dropOffLocation = dropOffAddress;
notifyListeners();
}
void updateTripsCounter(int tripCounter){
countTrips = tripCounter;
notifyListeners();
}
void updateTripKeys(List<String> newKeys){
tripHistoryKeys = newKeys;
notifyListeners();
}
void updateTripData(History eachhistory){
tripHistoryDataList.add(eachhistory);
notifyListeners();
}
}
and this is how i fetch data from the realtime database
static void retrieveHistory(context) {
//retrieve history and Trip History
newRequestsRef
.orderByChild("rider_name")
.once()
.then((DataSnapshot dataSnapshot) {
if (dataSnapshot.value != null) {
//update total number of trip to provider
Map<dynamic, dynamic> keys = dataSnapshot.value;
int tripCounter = keys.length;
Provider.of<AppData>(context, listen: false)
.updateTripsCounter(tripCounter);
//update trip keys of trip to provider
List<String> tripHistoryKeys = [];
keys.forEach((key, value) {
tripHistoryKeys.add(key);
});
Provider.of<AppData>(context, listen: false)
.updateTripKeys(tripHistoryKeys);
obtainTripRequestHistoryData(context);
}
});
}
static void obtainTripRequestHistoryData(context) {
var keys = Provider.of<AppData>(context, listen: false).tripHistoryKeys;
for (String key in keys) {
newRequestsRef.child(key).once().then((DataSnapshot dataSnapshot) {
if (dataSnapshot.value != null) {
newRequestsRef
.child(key)
.child("rider_name")
.once()
.then((DataSnapshot dsnap) {
String name = dsnap.value.toString();
if (name == userCurrentInfo.name) {
var history = History.fromSnapshot(dataSnapshot);
Provider.of<AppData>(context, listen: false).updateTripData(history);
}
});
}
});
}
}
[1]: https://i.stack.imgur.com/sRBAD.jpg
I think main() is the bug, should
void main() {
var colorProvider = ColorProvider();
var counterProvider = CounterProvider();
Provider.debugCheckInvalidValueType = null;
runApp(MultiProvider(
providers: [
ChangeNotifierProvider.value(value: colorProvider),
ChangeNotifierProvider.value(value: counterProvider),
],
child: MyApp(),
));
}
you can look my demo: https://github.com/pheromone/Flutter_learn_demo/tree/master/%E5%85%B6%E4%BB%96/state%E7%AE%A1%E7%90%86/provider_demo4.x
main.dart
import 'dart:io';
import 'package:audioplayer/audioplayer.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:path_provider/path_provider.dart';
import 'package:record_mp3/record_mp3.dart';
import 'package:permission_handler/permission_handler.dart';
import 'regitration.dart';
//import 'voiceCreate.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String statusText = "";
bool isComplete = false;
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Builder(
builder: (context) => Scaffold(
drawer: Drawer(
elevation: 2.0,
child: ListView(
children: <Widget>[
ListTile(
title: Text('Home'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return MyApp();
},
),
);
},
),
ListTile(
title: Text('Sign up'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LoginScreen();
},
),
);
},
),
ListTile(
title: Text('Sign in'),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) {
return LoginScreen();
},
),
);
// add sign in page
},
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.add),
backgroundColor: Colors.tealAccent.shade700,
),
backgroundColor: Colors.grey.shade900,
appBar: AppBar(
title: Text('Myvo'),
centerTitle: true,
backgroundColor: Colors.tealAccent.shade700,
),
body: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: GestureDetector(
child: IconButton(
icon: Icon(Icons.mic),
color: Colors.white,
iconSize: 40,
onPressed: () async {
startRecord();
}),
),
),
Expanded(
child: GestureDetector(
child: IconButton(
icon: Icon(Icons.pause),
color: Colors.white,
iconSize: 40,
onPressed: () async {
pauseRecord();
}),
),
),
Expanded(
child: GestureDetector(
child: IconButton(
icon: Icon(Icons.stop),
color: Colors.white,
iconSize: 40,
onPressed: () async {
stopRecord();
}),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: Text(
statusText,
style: TextStyle(color: Colors.red, fontSize: 20),
),
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
play();
},
child: Container(
margin: EdgeInsets.only(top: 30),
alignment: AlignmentDirectional.center,
width: 100,
height: 50,
child: isComplete && recordFilePath != null
? Text(
"play",
style: TextStyle(color: Colors.red, fontSize: 20),
)
: Container(),
),
),
]),
),
),
);
}
Future<bool> checkPermission() async {
if (!await Permission.microphone.isGranted) {
PermissionStatus status = await Permission.microphone.request();
if (status != PermissionStatus.granted) {
return false;
}
}
return true;
}
void startRecord() async {
bool hasPermission = await checkPermission();
if (hasPermission) {
statusText = "Recording...";
recordFilePath = await getFilePath();
isComplete = false;
RecordMp3.instance.start(recordFilePath, (type) {
statusText = "Record error--->$type";
setState(() {});
});
} else {
statusText = "No microphone permission";
}
setState(() {});
}
void pauseRecord() {
if (RecordMp3.instance.status == RecordStatus.PAUSE) {
bool s = RecordMp3.instance.resume();
if (s) {
statusText = "Recording...";
setState(() {});
}
} else {
bool s = RecordMp3.instance.pause();
if (s) {
statusText = "Recording pause...";
setState(() {});
}
}
}
void stopRecord() {
bool s = RecordMp3.instance.stop();
if (s) {
statusText = "Record complete";
isComplete = true;
setState(() {});
}
}
void resumeRecord() {
bool s = RecordMp3.instance.resume();
if (s) {
statusText = "Recording...";
setState(() {});
}
}
String recordFilePath;
void play() {
if (recordFilePath != null && File(recordFilePath).existsSync()) {
AudioPlayer audioPlayer = AudioPlayer();
audioPlayer.play(recordFilePath, isLocal: true);
}
}
int i = 0;
Future<String> getFilePath() async {
Directory storageDirectory = await getApplicationDocumentsDirectory();
String sdPath = storageDirectory.path + "/record";
var d = Directory(sdPath);
if (!d.existsSync()) {
d.createSync(recursive: true);
}
return sdPath + "/test_${i++}.mp3";
}
}
I want to call the VoiceCreate function when clicking on onPressed
voiceCreate.dart
import 'package:flutter/material.dart';
import 'main.dart';
class VoiceCreate extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
body: Center(
child: IconButton(
icon: Icon(Icons.mic),
color: Colors.white,
iconSize: 70,
onPressed: () {}),
),
),
);
}
}
I want to call startRecord method from main.dart when clicking on onPressed
If you check the code of IconButton you'll see that onPressed is a VoidCallback, you can try to imitate the logic to do the same
class VoiceCreate extends StatelessWidget {
final VoidCallback onPressed;
VoiceCreate({this.onPressed});
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
body: Center(
child: IconButton(
icon: Icon(Icons.mic),
color: Colors.white,
iconSize: 70,
onPressed: onPressed),
),
),
);
}
}
And in main just call your widget VoiceCreate with an onPressed parameter
VoiceCreate(
onPressed: () => startRecord
)
edited code here. Still the startRecord() is not working. VoiceCreate() is working
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return VoiceCreate(onPressed: startRecord);
}),
);
},
// Add your onPressed code here!
child: Icon(Icons.add),
backgroundColor: Colors.tealAccent.shade700,
),
class VoiceCreate extends StatelessWidget {
final VoidCallback onPressed;
VoiceCreate({this.onPressed});
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
body: Center(
child: IconButton(
icon: Icon(Icons.mic),
color: Colors.white,
iconSize: 70,
onPressed: onPressed),
),
),
);
}
}
You could do this by using shared view model across need widgets, like so:
I'd recommend to use this approach instead of callbacks and Stateful widgets
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class Parent extends StatelessWidget {
#override
Widget build(BuildContext context) {
return GetBuilder<CommonViewModel>(
init: CommonViewModel(),
builder: (model) {
return Scaffold(
body: Column(
children: [
RaisedButton(onPressed: () => model.parentMethod(0)),
RaisedButton(onPressed: () => model.childMethod('call from parent')),
],
),
);
},
);
}
}
class Child extends StatelessWidget {
#override
Widget build(BuildContext context) {
return GetBuilder<CommonViewModel>(
builder: (model) {
return Scaffold(
body: Column(
children: [
RaisedButton(onPressed: () => model.childMethod('call from child')),
RaisedButton(onPressed: () => model.parentMethod(100)),
],
),
);
},
);
}
}
class CommonViewModel extends GetxController {
void parentMethod(int argument) {
print('Parent method $argument');
}
void childMethod(String argument) {
print('Child method $argument');
}
}