но это не работает.
это мой код виджета MyApp, Home, SearchStore
Виджет MyApp
Код: Выделить всё
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: AppStyle().appTheme,
home: Scaffold(
body: FutureBuilder(
future: checkUserInfo(context),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: SvgPicture.asset(
'assets/brand/big_logo.svg',
),
);
} else if (snapshot.data!) {
return const Home();
} else {
return const SignIn();
}
},
),
),
);
}
}
Код: Выделить всё
class Home extends StatelessWidget {
const Home ({super.key});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'search store',
style: AppStyle().appTheme.textTheme.displayLarge,
),
SizedBox(
height: 20,
),
Hero(
tag: 'hero',
child: TextField(
readOnly: true,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => SearchStore(),
),
);
},
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
prefixIconColor: AppStyle().brandColor,
hintText: 'need store name',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: AppStyle().brandColor,
width: 1.5,
),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: AppStyle().brandColor,
width: 1.5,
),
borderRadius: BorderRadius.circular(15),
),
),
),
)
],
);
}
}
Код: Выделить всё
class SearchStore extends StatelessWidget {
const SearchStore({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Hero(
tag: 'hero',
child: TextField(
readOnly: false,
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
prefixIconColor: AppStyle().brandColor,
hintText: 'need store name',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: AppStyle().brandColor,
width: 1.5,
),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: AppStyle().brandColor,
width: 1.5,
),
borderRadius: BorderRadius.circular(15),
),
),
),
),
],
),
);
}
}
это стек вызовов ошибок
Код: Выделить всё
debugCheckHasMaterial. (c:\Users\jun\flutter\packages\flutter\lib\src\material\debug.dart:38)
debugCheckHasMaterial (c:\Users\jun\flutter\packages\flutter\lib\src\material\debug.dart:63)
_TextFieldState.build (c:\Users\jun\flutter\packages\flutter\lib\src\material\text_field.dart:1324)
StatefulElement.build (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5592)
ComponentElement.performRebuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5480)
StatefulElement.performRebuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5643)
Element.rebuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5196)
ComponentElement._firstBuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5462)
StatefulElement._firstBuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5634)
ComponentElement.mount (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5456)
Element.inflateWidget (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:4335)
Element.updateChild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:3846)
ComponentElement.performRebuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5505)
Element.rebuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5196)
ComponentElement._firstBuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5462)
ComponentElement.mount (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5456)
Element.inflateWidget (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:4335)
Element.updateChild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:3846)
ComponentElement.performRebuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5505)
StatefulElement.performRebuild (c:\Users\jun\flutter\packages\flutter\lib\src\widgets\framework.dart:5643
Код: Выделить всё
No Material widget found.
TextField widgets require a Material widget ancestor within the closest LookupBoundary.
In Material Design, most widgets are conceptually "printed" on a sheet of material. In Flutter's material library, that material is represented by the Material widget. It is the Material widget that renders ink splashes, for instance. Because of this, many material library widgets require that there be a Material widget in the tree above them.
To introduce a Material widget, you can either directly include one, or use a widget that contains Material itself, such as a Card, Dialog, Drawer, or Scaffold.
The specific widget that could not find a Material ancestor was: TextField
введите здесь описание изображения
что мне делать?
я думаю, что
textField нужен MaterialApp, но метод push Navigator -> новый UiStack в MateriApp -> Нет MaterialApp
- Оберните MaterialAPP и Scaffold
Код: Выделить всё
Hero(
tag: 'hero',
child: TextField(
readOnly: true,
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MaterialApp(
home: Scaffold(
body: SearchStore(),
),
),
),
);
},
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
prefixIconColor: AppStyle().brandColor,
hintText: 'need store name.',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: AppStyle().brandColor,
width: 1.5,
),
borderRadius: BorderRadius.circular(15),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: AppStyle().brandColor,
width: 1.5,
),
borderRadius: BorderRadius.circular(15),
),
),
),
)
я не знаю, что мне делать
Подробнее здесь: https://stackoverflow.com/questions/783 ... aterialapp