Advertisement
sanca

error_navigator

Sep 24th, 2020
1,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.13 KB | None | 0 0
  1. //File lib/main.dart
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:sanca_news/single_article.dart';
  5.  
  6. void main() {
  7.   runApp(MyApp());
  8. }
  9.  
  10. class MyApp extends StatefulWidget {
  11.   @override
  12.   _MyAppState createState() => _MyAppState();
  13. }
  14.  
  15. class _MyAppState extends State<MyApp> {
  16.   @override
  17.   Widget build(BuildContext context) {
  18.     return MaterialApp(
  19.       home: Scaffold(
  20.           // backgroundColor: Colors.green,
  21.           appBar: AppBar(
  22.         ...
  23.         ...
  24.           ),
  25.           body: Padding(
  26.             padding: const EdgeInsets.all(10.0),
  27.             child: ListView(
  28.               children: <Widget>[
  29.                 // card for newest articles
  30.                 Card(
  31.             ...
  32.             ...
  33.                 ),
  34.  
  35.                 Container(
  36.             ...
  37.             ...
  38.             ...
  39.                 ),
  40.  
  41.                 buildCard(),
  42.                 buildCard(),
  43.                 buildCard(),
  44.                 buildCard(),
  45.                 buildCard(),
  46.               ],
  47.             ),
  48.           )),
  49.     );
  50.   }
  51.  
  52.   String text =
  53.       "Ini text beritanya Ini text beritanya Ini text beritanya Ini text ...";
  54.  
  55.   Card buildCard() {
  56.     return Card(
  57.       shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  58.       elevation: 5,
  59.       child: Row(
  60.         mainAxisAlignment: MainAxisAlignment.spaceAround,
  61.         children: [
  62.           Flexible(
  63.               flex: 2,
  64.               child: Container(
  65.                   margin: EdgeInsets.all(5),
  66.                   child: Column(
  67.                     crossAxisAlignment: CrossAxisAlignment.start,
  68.                     children: [
  69.                       Text(
  70.                         text,
  71.                         style: TextStyle(
  72.                             fontSize: 12,
  73.                             fontWeight: FontWeight.w700,
  74.                             fontFamily: "Poppins"),
  75.                       ),
  76.                       Container(
  77.                         margin: EdgeInsets.only(top: 5),
  78.                         child: RaisedButton(
  79.                           onPressed: () {
  80.                             Navigator.push(
  81.                                 context,
  82.                                 MaterialPageRoute(
  83.                                     builder: (BuildContext context) =>
  84.                                         SingleArticle()));
  85.                           },
  86.                           child: Text(
  87.                             "Read more ...",
  88.                             style: TextStyle(fontFamily: "Poppins"),
  89.                           ),
  90.                         ),
  91.                       )
  92.                     ],
  93.                   ))),
  94.           Flexible(
  95.         ...
  96.         ...
  97.         ),
  98.         ],
  99.       ),
  100.     );
  101.   }
  102. }
  103.  
  104.  
  105.  
  106. //File single_article.dart
  107. import 'package:flutter/material.dart';
  108.  
  109. class SingleArticle extends StatelessWidget {
  110.   @override
  111.   Widget build(BuildContext context) {
  112.     return MaterialApp(
  113.       home: Scaffold(
  114.         appBar: AppBar(
  115.           title: Text("Halaman Single Article"),
  116.         ),
  117.         body: Center(
  118.           child: Text("Halaman Single Article"),
  119.         ),
  120.       ),
  121.     );
  122.   }
  123. }
  124.  
  125.  
  126. //Error yang muncul:
  127.  
  128. ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
  129. The following assertion was thrown while handling a gesture:
  130. Navigator operation requested with a context that does not include a Navigator.
  131. The context used to push or pop routes from the Navigator must be that of a widget that is a
  132. descendant of a Navigator widget.
  133. When the exception was thrown, this was the stack:
  134. ...
  135. ...
  136.  
  137. (elided 3 frames from dart:async)
  138. Handler: "onTap"
  139. Recognizer:
  140.   TapGestureRecognizer#e04f5
  141.  
  142. ═══════ Exception caught by gesture ═══════════════════════════════════════════
  143. The following assertion was thrown while handling a gesture:
  144. Navigator operation requested with a context that does not include a Navigator.
  145.  
  146. ...
  147. ...
  148.  
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement